ARM7 based quadrocopter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.1KB

  1. #ifndef AT91TWI_H_
  2. #define AT91TWI_H_
  3. #include <stdint.h>
  4. /* TWI slave addresses */
  5. #define TWI_ADDR_BL1 0x21
  6. #define TWI_ADDR_BL2 0x22
  7. #define TWI_ADDR_BL3 0x23
  8. #define TWI_ADDR_BL4 0x24
  9. #define TWI_ADDR_EEPROM 0x50
  10. /* TWIBOOT commands */
  11. #define CMD_WAIT 0x00
  12. #define CMD_GET_INFO 0x10
  13. #define CMD_GET_SIGNATURE 0x11
  14. #define CMD_WRITE_FLASH 0x12
  15. #define CMD_READ_FLASH 0x13
  16. #define CMD_WRITE_EEPROM 0x14
  17. #define CMD_READ_EEPROM 0x15
  18. #define CMD_BOOT_APPLICATION 0x1F
  19. /* blctrl commands */
  20. //#define CMD_WAIT 0x00
  21. //#define CMD_GET_INFO 0x10
  22. #define CMD_SET_PWM 0x21
  23. #define CMD_GET_STATUS 0x22
  24. #define CMD_SET_PARAM 0x23
  25. #define CMD_GET_PARAM 0x24
  26. #define CMD_BOOT_LOADER 0x2F
  27. struct blmc_status {
  28. uint8_t pwm_ist;
  29. uint8_t pwm_soll;
  30. uint16_t rpm;
  31. uint16_t current;
  32. uint16_t voltage;
  33. } __attribute__ ((packed));
  34. struct blmc_param {
  35. uint16_t spinup_ticks;
  36. uint8_t spinup_tick;
  37. uint8_t spinup_step;
  38. uint8_t spinup_wait;
  39. uint8_t spinup_pwm;
  40. uint8_t pwm_min;
  41. uint8_t pwm_max;
  42. uint16_t current_limit;
  43. uint16_t current_max;
  44. uint16_t voltage_min;
  45. uint16_t crc16;
  46. } __attribute__ ((packed));
  47. #define EE_PARAMETER_SET_START 0x0000
  48. /* remote control calibration data */
  49. #define EE_RC_CAL_DATA (EE_PARAMETER_SET_START)
  50. #define EE_RC_CAL_DATA_SIZE 48
  51. /* ACC calibration data */
  52. #define EE_ACC_CAL_DATA (EE_RC_CAL_DATA + EE_RC_CAL_DATA_SIZE)
  53. #define EE_ACC_CAL_DATA_SIZE 6
  54. #define EE_PARAMETER_SET_END (EE_ACC_CAL_DATA + EE_ACC_CAL_DATA_SIZE)
  55. struct twi_cmd {
  56. uint32_t cmd; /* cmd byte(s) */
  57. uint8_t mode; /* read/write, cmdlen (1-3 bytes) */
  58. uint16_t size; /* data size */
  59. uint8_t *data; /* read/write data */
  60. };
  61. /* same bits as TWI_MMR[8..15] */
  62. #define TWI_MODE_READ 0x10
  63. #define TWI_MODE_WRITE 0x00
  64. #define TWI_MODE_0_ARG 0x01
  65. #define TWI_MODE_1_ARG 0x02
  66. #define TWI_MODE_2_ARG 0x03
  67. uint32_t twi_read_eeprom(uint32_t addr, uint8_t *buf, uint32_t size);
  68. uint32_t twi_write_eeprom(uint32_t addr, uint8_t *buf, uint32_t size);
  69. uint32_t twi_setpwm(uint8_t *values);
  70. uint32_t twi_cmd(uint8_t addr, struct twi_cmd *cmd);
  71. void at91_twi_init(void);
  72. void at91_twi_test(void);
  73. #endif /*AT91TWI_H_*/