Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1734 | - | 1 | #ifndef _I2C_MASTER_H |
2 | #define _I2C_MASTER_H |
||
3 | |||
4 | |||
5 | #include <inttypes.h> |
||
6 | #include "mk-data-structs.h" |
||
7 | |||
8 | #define TWI_STATE_MOTOR_TX 0 |
||
9 | #define TWI_STATE_MOTOR_RX 5 |
||
10 | #define TWI_STATE_GYRO_OFFSET_TX 18 |
||
11 | |||
12 | extern volatile uint8_t twi_state; |
||
13 | extern volatile uint8_t motor_write; |
||
14 | extern volatile uint8_t motor_read; |
||
15 | extern volatile uint8_t I2C_TransferActive; |
||
16 | |||
17 | extern uint8_t MissingMotor; |
||
18 | |||
19 | #define MAX_MOTORS 12 |
||
20 | #define MOTOR_STATE_PRESENT_MASK 0x80 |
||
21 | #define MOTOR_STATE_ERROR_MASK 0x7F |
||
22 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
||
23 | #define BLFLAG_TX_COMPLETE 0x01 |
||
24 | #define BLFLAG_READ_VERSION 0x02 |
||
25 | |||
26 | extern volatile uint8_t BLFlags; |
||
27 | extern char MotorenEin; |
||
28 | unsigned char MotorTest[16]; |
||
29 | #define BL_READMODE_STATUS 0 |
||
30 | #define BL_READMODE_CONFIG 16 |
||
31 | |||
32 | |||
33 | |||
34 | extern MotorData_t Motor[MAX_MOTORS]; |
||
35 | |||
36 | #define BLCONFIG_REVISION 2 |
||
37 | |||
38 | #define MASK_SET_PWM_SCALING 0x01 |
||
39 | #define MASK_SET_CURRENT_LIMIT 0x02 |
||
40 | #define MASK_SET_TEMP_LIMIT 0x04 |
||
41 | #define MASK_SET_CURRENT_SCALING 0x08 |
||
42 | #define MASK_SET_BITCONFIG 0x10 |
||
43 | #define MASK_RESET_CAPCOUNTER 0x20 |
||
44 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
||
45 | #define MASK_SET_SAVE_EEPROM 0x80 |
||
46 | |||
47 | #define BITCONF_REVERSE_ROTATION 0x01 |
||
48 | #define BITCONF_RES1 0x02 |
||
49 | #define BITCONF_RES2 0x04 |
||
50 | #define BITCONF_RES3 0x08 |
||
51 | #define BITCONF_RES4 0x10 |
||
52 | #define BITCONF_RES5 0x20 |
||
53 | #define BITCONF_RES6 0x40 |
||
54 | #define BITCONF_RES7 0x80 |
||
55 | |||
56 | |||
57 | |||
58 | extern BLConfig_t BLConfig; |
||
59 | |||
60 | extern volatile uint16_t I2CTimeout; |
||
61 | |||
62 | void I2C_Init(char); // Initialize I2C |
||
63 | #define I2C_Start(start_state) {twi_state = start_state; BLFlags &= ~BLFLAG_TX_COMPLETE; TWCR = (1<<TWSTA) | (1<<TWEN) | (1<<TWINT) | (1<<TWIE);} |
||
64 | #define I2C_Stop(start_state) {twi_state = start_state; TWCR = (1<<TWEN) | (1<<TWSTO) | (1<<TWINT);} |
||
65 | void I2C_Reset(void); // Reset I2C |
||
66 | |||
67 | #define BLCONFIG_SUCCESS 0 |
||
68 | #define BLCONFIG_ERR_MOTOR_RUNNING 1 |
||
69 | #define BLCONFIG_ERR_MOTOR_NOT_EXIST 2 |
||
70 | #define BLCONFIG_ERR_HW_NOT_COMPATIBLE 3 |
||
71 | #define BLCONFIG_ERR_SW_NOT_COMPATIBLE 4 |
||
72 | #define BLCONFIG_ERR_CHECKSUM 5 |
||
73 | #define BLCONFIG_ERR_READ_NOT_POSSIBLE 6 |
||
74 | |||
75 | uint8_t I2C_WriteBLConfig(uint8_t motor); |
||
76 | uint8_t I2C_ReadBLConfig(uint8_t motor); |
||
77 | |||
78 | #endif |
||
79 | |||
80 |