b561b86f3b
2. dev mode commands (except those already available to users) start with 3xxxFFFF
191 lines
4.0 KiB
C
191 lines
4.0 KiB
C
#include "max14802.h"
|
|
#include "elite_board.h"
|
|
|
|
#include "nrf_delay.h"
|
|
#include "nrf_gpio.h"
|
|
|
|
#include "string.h"
|
|
|
|
#pragma GCC optimize("O2")
|
|
|
|
#if (DEF_MAX14802_ENABLED)
|
|
|
|
static sw_t m_sw = { .val = UINT64_MAX };
|
|
|
|
#define EXCLUDE_IO_ENABLE 1
|
|
#define EXCLUDE_IO_DISABLE 0
|
|
|
|
static const uint32_t exclude_io[64] = {
|
|
ADPT0_S1_PIN,
|
|
ADPT0_S2_PIN,
|
|
ADPT0_S3_PIN,
|
|
ADPT0_S4_PIN,
|
|
ADPT1_S1_PIN,
|
|
ADPT1_S2_PIN,
|
|
ADPT1_S3_PIN,
|
|
ADPT1_S4_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
UNCONNECTED_PIN,
|
|
};
|
|
|
|
static void shift_out(uint8_t *p, uint32_t len)
|
|
{
|
|
nrf_gpio_pin_clear(ADPT_LE_PIN);
|
|
|
|
for (int32_t j = len; j > 0; j--)
|
|
{
|
|
uint32_t val = p[j - 1];
|
|
for (uint32_t i = 0x01 << (SW_PER_BYTE - 1); i > 0; i >>= 1)
|
|
{
|
|
nrf_gpio_pin_clear(ADPT_CLK_PIN);
|
|
nrf_gpio_pin_write(ADPT_DIN_PIN, val & i);
|
|
nrf_gpio_pin_set(ADPT_CLK_PIN);
|
|
nrf_gpio_pin_write(ADPT_DIN_PIN, val & i);
|
|
}
|
|
}
|
|
|
|
nrf_gpio_pin_clear(ADPT_CLK_PIN);
|
|
nrf_gpio_pin_clear(ADPT_DIN_PIN);
|
|
nrf_gpio_pin_set(ADPT_LE_PIN);
|
|
nrf_gpio_pin_clear(ADPT_LE_PIN);
|
|
}
|
|
|
|
int max14802_reset(void)
|
|
{
|
|
m_sw.val = 0;
|
|
shift_out((uint8_t *)&m_sw.val, SW_TOTAL_COUNT / SW_PER_BYTE);
|
|
return 0;
|
|
}
|
|
|
|
int max14802_write(sw_t sw_mask)
|
|
{
|
|
if (m_sw.val != sw_mask.val)
|
|
{
|
|
m_sw = sw_mask;
|
|
|
|
// Disable A1_AOUT,A2_AOUT,B1_AOUT, .... B3_AOUT, B4_AOUT
|
|
|
|
for (uint32_t i = 0; i < SW_TOTAL_COUNT; i++)
|
|
{
|
|
nrf_gpio_pin_write(exclude_io[i], EXCLUDE_IO_DISABLE);
|
|
}
|
|
|
|
nrf_delay_ms(1);
|
|
|
|
// Set max14082
|
|
shift_out((uint8_t *)&m_sw.val, SW_TOTAL_COUNT / SW_PER_BYTE);
|
|
|
|
// Enable A1_AOUT,A2_AOUT,B1_AOUT, .... B3_AOUT, B4_AOUT are all disable when all max14082 off
|
|
|
|
if (m_sw.val == 0)
|
|
{
|
|
nrf_delay_ms(1);
|
|
for (uint32_t i = 0; i < SW_TOTAL_COUNT; i++)
|
|
{
|
|
nrf_gpio_pin_write(exclude_io[i], EXCLUDE_IO_ENABLE);
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int max14802_read(sw_t *p_sw_mask)
|
|
{
|
|
*p_sw_mask = m_sw;
|
|
return 0;
|
|
}
|
|
int max14802_get_sw_count(uint32_t *p_sw_count)
|
|
{
|
|
*p_sw_count = SW_TOTAL_COUNT;
|
|
return 0;
|
|
}
|
|
|
|
int max14802_init(void)
|
|
{
|
|
nrf_gpio_pin_set(ADPT_CLR_PIN);
|
|
nrf_gpio_pin_clear(ADPT_LE_PIN);
|
|
nrf_gpio_pin_clear(ADPT_CLK_PIN);
|
|
nrf_gpio_pin_clear(ADPT_DIN_PIN);
|
|
|
|
nrf_gpio_cfg_output(ADPT_CLR_PIN);
|
|
nrf_gpio_cfg_output(ADPT_LE_PIN);
|
|
nrf_gpio_cfg_output(ADPT_CLK_PIN);
|
|
nrf_gpio_cfg_output(ADPT_DIN_PIN);
|
|
|
|
for (uint32_t i = 0; i < COUNTOF(exclude_io); i++)
|
|
{
|
|
nrf_gpio_pin_write(exclude_io[i], EXCLUDE_IO_DISABLE);
|
|
}
|
|
|
|
max14802_write((sw_t) { .val = 0 });
|
|
|
|
nrf_gpio_pin_clear(ADPT_CLR_PIN);
|
|
|
|
return 0;
|
|
}
|
|
|
|
const sw_drv_if_t max14802 = {
|
|
.init = max14802_init,
|
|
.reset = max14802_reset,
|
|
.write = max14802_write,
|
|
.read = max14802_read,
|
|
.get_sw_count = max14802_get_sw_count,
|
|
};
|
|
|
|
#endif
|