86 lines
1.8 KiB
C
86 lines
1.8 KiB
C
#ifndef AT91TWI_H_
|
|
#define AT91TWI_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
/* TWI slave addresses */
|
|
#define TWI_ADDR_BL1 0x21
|
|
#define TWI_ADDR_BL2 0x22
|
|
#define TWI_ADDR_BL3 0x23
|
|
#define TWI_ADDR_BL4 0x24
|
|
#define TWI_ADDR_EEPROM 0x50
|
|
|
|
/* TWIBOOT commands */
|
|
#define CMD_WAIT 0x00
|
|
#define CMD_GET_INFO 0x10
|
|
#define CMD_GET_SIGNATURE 0x11
|
|
#define CMD_WRITE_FLASH 0x12
|
|
#define CMD_READ_FLASH 0x13
|
|
#define CMD_WRITE_EEPROM 0x14
|
|
#define CMD_READ_EEPROM 0x15
|
|
#define CMD_BOOT_APPLICATION 0x1F
|
|
|
|
/* blctrl commands */
|
|
//#define CMD_WAIT 0x00
|
|
//#define CMD_GET_INFO 0x10
|
|
#define CMD_SET_PWM 0x21
|
|
#define CMD_GET_STATUS 0x22
|
|
#define CMD_SET_PARAM 0x23
|
|
#define CMD_GET_PARAM 0x24
|
|
#define CMD_BOOT_LOADER 0x2F
|
|
|
|
struct blmc_status {
|
|
uint8_t pwm_ist;
|
|
uint8_t pwm_soll;
|
|
|
|
uint16_t rpm;
|
|
uint16_t current;
|
|
uint16_t voltage;
|
|
} __attribute__ ((packed));
|
|
|
|
struct blmc_param {
|
|
uint16_t spinup_ticks;
|
|
|
|
uint8_t spinup_tick;
|
|
uint8_t spinup_step;
|
|
|
|
uint8_t spinup_wait;
|
|
uint8_t spinup_pwm;
|
|
|
|
uint8_t pwm_min;
|
|
uint8_t pwm_max;
|
|
|
|
uint16_t current_limit;
|
|
uint16_t current_max;
|
|
|
|
uint16_t voltage_min;
|
|
|
|
uint16_t crc16;
|
|
} __attribute__ ((packed));
|
|
|
|
struct twi_cmd {
|
|
uint32_t cmd; /* cmd byte(s) */
|
|
uint8_t mode; /* read/write, cmdlen (1-3 bytes) */
|
|
uint16_t size; /* data size */
|
|
uint8_t *data; /* read/write data */
|
|
};
|
|
|
|
/* same bits as TWI_MMR[8..15] */
|
|
#define TWI_MODE_READ 0x10
|
|
#define TWI_MODE_WRITE 0x00
|
|
#define TWI_MODE_0_ARG 0x01
|
|
#define TWI_MODE_1_ARG 0x02
|
|
#define TWI_MODE_2_ARG 0x03
|
|
|
|
uint32_t twi_read_eeprom(uint32_t addr, uint8_t *buf, uint32_t size);
|
|
uint32_t twi_write_eeprom(uint32_t addr, uint8_t *buf, uint32_t size);
|
|
|
|
uint32_t twi_setpwm(uint8_t *values);
|
|
|
|
uint32_t twi_cmd(uint8_t addr, struct twi_cmd *cmd);
|
|
|
|
void at91_twi_init(void);
|
|
void at91_twi_test(void);
|
|
|
|
#endif /*AT91TWI_H_*/
|