Skip to content

Commit

Permalink
parametrize the ssp data size
Browse files Browse the repository at this point in the history
  • Loading branch information
yconst committed Apr 15, 2024
1 parent afb60d0 commit e4512a2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion firmware/src/sensor/amt22.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool amt22_init_with_port(Sensor *s, const SSP_TYPE port, PAC55XX_SSP_TYPEDEF *s
bool amt22_init_with_config(Sensor *s, const AMT22SensorConfig *c) {
AMT22Sensor *as = (AMT22Sensor *)s;
as->config = *c;
ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, 0, 0);
ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, SSP_DATA_SIZE_8, 0, 0);
delay_us(10000);

amt22_send_angle_cmd(s);
Expand Down
7 changes: 7 additions & 0 deletions firmware/src/sensor/amt22.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ static inline uint8_t amt22_get_errors(const Sensor *s)

static inline void amt22_send_angle_cmd(const Sensor *s)
{
// AMT22 has specific timing requirements with respect to reading
// the first and second bytes of the angle. For this reason we
// insert the 6us delay that corresponds to the datasheet-specified
// 3us + an experimentally defined value to account for transmission
// delay.
ssp_write_one(((const AMT22Sensor *)s)->config.ssp_struct, AMT22_CMD_READ_ANGLE);
delay_us(6);
ssp_write_one(((const AMT22Sensor *)s)->config.ssp_struct, AMT22_CMD_READ_ANGLE);
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/src/sensor/as5047.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool as5047p_init_with_port(Sensor *s, const SSP_TYPE port, PAC55XX_SSP_TYPEDEF
bool as5047p_init_with_config(Sensor *s, const AS5047PSensorConfig *c) {
AS5047PSensor *as = (AS5047PSensor *)s;
as->config = *c;
ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, 1, 0);
ssp_init(as->config.ssp_port, SSP_MS_MASTER, 16, SSP_DATA_SIZE_16, 1, 0);
delay_us(10000); // Example delay, adjust based on AS5047P datasheet

as5047p_send_angle_cmd(s);
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/sensor/ma7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool ma7xx_init_with_port(Sensor *s, const SSP_TYPE port, PAC55XX_SSP_TYPEDEF *s
{
MA7xxSensor *ms = (MA7xxSensor *)s;
ms->config = *c;
ssp_init(ms->config.ssp_port, SSP_MS_MASTER, 4, 0, 0);
ssp_init(ms->config.ssp_port, SSP_MS_MASTER, 4, SSP_DATA_SIZE_16, 0, 0);
delay_us(16000); // ensure 16ms sensor startup time as per the datasheet
ma7xx_send_angle_cmd(s);
ma7xx_update(s, false);
Expand Down
4 changes: 2 additions & 2 deletions firmware/src/ssp/ssp_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ void ssp_interrupt_disable(SSP_TYPE ssp)
}
}

void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint8_t cph, uint8_t cpol)
void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint32_t data_size, uint8_t cph, uint8_t cpol)
{
PAC55XX_SSP_TYPEDEF *ssp_ptr;

Expand Down Expand Up @@ -804,7 +804,7 @@ void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint8_t cph,
ssp_ptr->CON.LBM = SSP_LP_NORMAL; // Loopback Mode, no loopback mode
ssp_ptr->CON.CPH = cph; // Clock Out Phase
ssp_ptr->CON.CPO = cpol; // Clock Out Polarity
ssp_ptr->CON.DSS = SSP_DATA_SIZE_16; // Data Size Select, 16 bit data
ssp_ptr->CON.DSS = data_size; // Data Size Select
ssp_ptr->CON.SOD = SSP_OUTPUT_NOT_DRIVE; // Slave Output Disable

ssp_io_config(ssp, ms_mode);
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/ssp/ssp_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef enum
volatile uint16_t ssp_data[10];
volatile uint16_t data_num;

extern void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint8_t cph, uint8_t cpol);
extern void ssp_init(SSP_TYPE ssp, SSP_MS_TYPE ms_mode, uint8_t clkn_div, uint32_t data_size, uint8_t cph, uint8_t cpol);
extern void ssp_deinit(SSP_TYPE ssp);
extern uint32_t ssp_write_one(PAC55XX_SSP_TYPEDEF *ssp_ptr, uint16_t data);
extern uint32_t ssp_write_multi(PAC55XX_SSP_TYPEDEF *ssp_ptr, uint16_t *data, uint32_t byte_num);
Expand Down

0 comments on commit e4512a2

Please sign in to comment.