b561b86f3b
2. dev mode commands (except those already available to users) start with 3xxxFFFF
50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
#include "tw1508.h"
|
|
|
|
#include "nrf_delay.h"
|
|
#include "nrf_log.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
#if (DEF_TW1508_ENABLED)
|
|
|
|
void tw1508_set(uint16_t out_0, uint16_t out_1)
|
|
{
|
|
NRF_LOG_INFO("%s(0x%04X, 0x%04X)", __FUNCTION__, out_0, out_1);
|
|
typedef struct
|
|
{
|
|
uint32_t scki_pin;
|
|
uint32_t sdi_pin;
|
|
uint32_t val;
|
|
} tw1805_t;
|
|
|
|
tw1805_t tw1508[2] = {
|
|
{TW_SCKI_0_PIN, TW_SDI_PIN, out_0},
|
|
{TW_SCKI_1_PIN, TW_SDI_PIN, out_1},
|
|
};
|
|
|
|
nrf_gpio_pin_write(tw1508[0].scki_pin, 0);
|
|
nrf_gpio_pin_write(tw1508[1].scki_pin, 0);
|
|
|
|
for (uint32_t i = 0; i < COUNTOF(tw1508); i++)
|
|
{
|
|
for (uint16_t j = 0b1000000000; j > 0; j >>= 1)
|
|
{
|
|
nrf_delay_us(1);
|
|
nrf_gpio_pin_write(tw1508[i].sdi_pin, j & tw1508[i].val);
|
|
nrf_delay_us(1);
|
|
nrf_gpio_pin_write(tw1508[i].scki_pin, 1);
|
|
nrf_delay_us(1);
|
|
nrf_gpio_pin_write(tw1508[i].scki_pin, 0);
|
|
}
|
|
}
|
|
nrf_delay_us(256);
|
|
}
|
|
|
|
void tw1508_init(void)
|
|
{
|
|
tw1508_set(0, 0);
|
|
}
|
|
|
|
#endif /* ! DEF_TW1508_ENABLED */
|