Files
microchip-application-bmd38…/adgs1412.c
T
2024-06-27 21:30:37 +08:00

72 lines
1.5 KiB
C

#include "adgs1412.h"
#include "elite_board.h"
#include "nrf_delay.h"
#if (DEF_ADGS1412_ENABLED)
#define DAISY_CHAIN_MODE 0x2500
static sw_t m_sw;
static int adgs1412_reset(void)
{
// the datasheet lacks clarity, RST_SW_PIN needs to be delayed after the motion signal
nrf_gpio_pin_clear(RST_SW_PIN);
nrf_delay_ms(1);
nrf_gpio_pin_set(RST_SW_PIN);
nrf_delay_ms(1);
return 0;
}
static int adgs1412_write(sw_t sw_mask)
{
uint8_t cmd[ASGS1412_COUNT];
uint64_t val = m_sw.val = sw_mask.val;
for (int i = 1; i <= ASGS1412_COUNT; i++)
{
cmd[sizeof(cmd) - i] = val & ((0x01 << SW_PER_BYTE) - 1);
val = val >> 4;
}
spim_xfer(CS_SW_PIN, NRF_SPIM_MODE_0, (uint8_t *)cmd, sizeof(cmd), NULL, 0);
return 0;
}
static int adgs1412_read(sw_t *p_sw_mask)
{
*p_sw_mask = m_sw;
return 0;
}
static int adgs1412_get_sw_count(uint32_t *p_sw_cnt)
{
*p_sw_cnt = SW_TOTAL_COUNT;
return 0;
}
static int adgs1412_init(void)
{
/* reset */
adgs1412_reset();
/* enter daisy chain mode */
uint16_t cmd = __REV16(DAISY_CHAIN_MODE);
spim_xfer(CS_SW_PIN, NRF_SPIM_MODE_0, (uint8_t *)&cmd, sizeof(cmd), NULL, 0);
/* sw status initialize */
m_sw.val = 0;
adgs1412_write(m_sw);
return 0;
}
const sw_drv_if_t adgs1412 = {
.init = adgs1412_init,
.reset = adgs1412_reset,
.write = adgs1412_write,
.read = adgs1412_read,
.get_sw_count = adgs1412_get_sw_count,
};
#endif /* ! DEF_ADGS1412_ENABLED */