df1b866d5a
1. 為了避免共用腳位代來的影響, 先將 spi driver 移除, 日後再補上
49 lines
1.0 KiB
C
49 lines
1.0 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)
|
|
{
|
|
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 tw1805_init(void)
|
|
{
|
|
tw1508_set(0, 0);
|
|
}
|
|
|
|
#endif /* ! DEF_TW1508_ENABLED */
|