Rev 1657 | Rev 1665 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1657 | Rev 1662 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | /*############################################################################ |
- | |
2 | ############################################################################*/ |
- | |
3 | - | ||
4 | #ifndef _I2C_MASTER_H |
1 | #ifndef _I2C_MASTER_H |
5 | #define _I2C_MASTER_H |
2 | #define _I2C_MASTER_H |
- | 3 | ||
- | 4 | ||
- | 5 | #include <inttypes.h> |
|
- | 6 | ||
- | 7 | #define TWI_STATE_MOTOR_TX 0 |
|
- | 8 | #define TWI_STATE_MOTOR_RX 5 |
|
Line -... | Line 9... | ||
- | 9 | #define TWI_STATE_GYRO_OFFSET_TX 18 |
|
6 | 10 | ||
- | 11 | extern volatile uint8_t twi_state; |
|
Line 7... | Line -... | ||
7 | //############################################################################ |
- | |
8 | - | ||
9 | // I2C Konstanten |
- | |
10 | #define SCL_CLOCK 200000L |
- | |
11 | #define I2C_TIMEOUT 30000 |
- | |
12 | #define I2C_START 0x08 |
- | |
13 | #define I2C_REPEATED_START 0x10 |
- | |
14 | #define I2C_TX_SLA_ACK 0x18 |
- | |
15 | #define I2C_TX_DATA_ACK 0x28 |
- | |
16 | #define I2C_RX_SLA_ACK 0x40 |
- | |
17 | #define I2C_RX_DATA_ACK 0x50 |
- | |
18 | 12 | extern volatile uint8_t motor_write; |
|
19 | //############################################################################ |
- | |
20 | 13 | extern volatile uint8_t motor_read; |
|
21 | extern volatile unsigned char twi_state; |
- | |
Line 22... | Line 14... | ||
22 | extern volatile unsigned char motor,MissingMotor; |
14 | |
23 | extern volatile unsigned char motorread; |
15 | |
24 | 16 | extern uint8_t MissingMotor; |
|
Line 25... | Line 17... | ||
25 | #define MAX_MOTORS 12 |
17 | |
Line 26... | Line 18... | ||
26 | #define MOTOR_STATE_PRESENT_MASK 0x80 |
18 | #define MAX_MOTORS 12 |
27 | #define MOTOR_STATE_ERROR_MASK 0x7F |
19 | #define MOTOR_STATE_PRESENT_MASK 0x80 |
28 | - | ||
Line 29... | Line 20... | ||
29 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
20 | #define MOTOR_STATE_ERROR_MASK 0x7F |
Line 30... | Line 21... | ||
30 | 21 | ||
31 | #define BLFLAG_READ_VERSION 0x01 |
22 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
- | 23 | ||
32 | #define BLFLAG_SEND_CONFIG 0x02 |
24 | #define BLFLAG_TX_COMPLETE 0x01 |
- | 25 | #define BLFLAG_READ_VERSION 0x02 |
|
33 | #define BLFLAG_TX_COMPLETE 0x04 |
26 | |
- | 27 | extern volatile uint8_t BLFlags; |
|
34 | 28 | ||
35 | extern volatile unsigned char BLFlags; |
29 | typedef struct |
36 | 30 | { |
|
37 | typedef struct |
- | |
38 | { |
- | |
39 | unsigned char SetPoint; // written by attitude controller |
31 | uint8_t Version; // the version of the BL (0 = old) |
Line 40... | Line 32... | ||
40 | unsigned char State; // 7 bit for I2C error counter, highest bit indicates if motor is present |
32 | uint8_t SetPoint; // written by attitude controller |
Line -... | Line 33... | ||
- | 33 | uint8_t SetPointLowerBits; // for higher Resolution of new BLs |
|
- | 34 | uint8_t State; // 7 bit for I2C error counter, highest bit indicates if motor is present |
|
- | 35 | // the following bytes must be exactly in that order! |
|
- | 36 | uint8_t Current; // in 0.1 A steps, read back from BL |
|
- | 37 | uint8_t MaxPWM; // read back from BL is less than 255 if BL is in current limit |
|
- | 38 | int8_t Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in °C |
|
- | 39 | } __attribute__((packed)) MotorData_t; |
|
- | 40 | ||
- | 41 | extern MotorData_t Motor[MAX_MOTORS]; |
|
- | 42 | ||
- | 43 | #define BLCONFIG_REVISION 1 |
|
- | 44 | ||
41 | unsigned char Current; // in 0.1 A steps, read back from BL |
45 | #define MASK_SET_PWM_SCALING 0x01 |
- | 46 | #define MASK_SET_CURRENT_LIMIT 0x02 |
|
- | 47 | #define MASK_SET_TEMP_LIMIT 0x04 |
|
- | 48 | #define MASK_SET_CURRENT_SCALING 0x08 |
|
- | 49 | #define MASK_SET_BITCONFIG 0x10 |
|
- | 50 | #define MASK_RESET_CAPCOUNTER 0x20 |
|
- | 51 | #define MASK_SET_DEFAULT_PARAMS 0x40 |
|
- | 52 | #define MASK_SET_SAVE_EEPROM 0x80 |
|
- | 53 | ||
- | 54 | #define BITCONF_REVERSE_ROTATION 0x01 |
|
- | 55 | #define BITCONF_RES1 0x02 |
|
- | 56 | #define BITCONF_RES2 0x04 |
|
- | 57 | #define BITCONF_RES3 0x08 |
|
42 | unsigned char MaxPWM; // read back from BL is less than 255 if BL is in current limit |
58 | #define BITCONF_RES4 0x10 |
- | 59 | #define BITCONF_RES5 0x20 |
|
43 | unsigned char Temperature; // old BL-Ctrl will return a 255 here |
60 | #define BITCONF_RES6 0x40 |
- | 61 | #define BITCONF_RES7 0x80 |
|
- | 62 | ||
- | 63 | typedef struct |
|
- | 64 | { |
|
44 | unsigned char SetPointLowerBits; // for higher Resolution |
65 | uint8_t Revision; // must be BL_REVISION |
- | 66 | uint8_t SetMask; // settings mask |
|
45 | unsigned char Version; |
67 | uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit |
46 | } __attribute__((packed)) MotorData_t; |
68 | uint8_t CurrentLimit; // current limit in A |
- | 69 | uint8_t TempLimit; // in °C |
|
47 | 70 | uint8_t CurrentScaling; // scaling factor for current measurement |
|
48 | extern MotorData_t Motor[MAX_MOTORS]; |
71 | uint8_t BitConfig; // see defines above |
49 | 72 | uint8_t crc; // checksum |
|
50 | void i2c_reset(void); |
73 | } __attribute__((packed)) BLConfig_t; |
51 | extern void i2c_init (void); // I2C initialisieren |
74 | |
Line 52... | Line 75... | ||
52 | extern void i2c_write_byte (char byte); // 1 Byte schreiben |
75 | extern BLConfig_t BLConfig; |