stash
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
j3d1 2022-09-07 22:31:04 +02:00
parent 15e4f6dfc7
commit 75060bc8a8

View file

@ -14,8 +14,9 @@
const int signal_led_pin = 2; const int signal_led_pin = 2;
const int cs0 = 15; const int cs0 = 15;
const int gpio4 = 4; const int nint_pin = 4;
const int gpio5 = 5; const int init_pin = 5;
extern "C" void signal_led(bool state) { extern "C" void signal_led(bool state) {
gpio_write(signal_led_pin, !state); gpio_write(signal_led_pin, !state);
@ -27,31 +28,41 @@ void int_to_hex(uint8_t i, char buf[2]) {
buf[1] = hex_charset[i & 0x0F]; buf[1] = hex_charset[i & 0x0F];
} }
const gpio_inttype_t int_type = GPIO_INTTYPE_EDGE_NEG;
void gpio_intr_handler(uint8_t gpio_num)
{
uint8_t buf[2];
spi_read(1, 0x0000, buf, 2, SPI_8BIT);
char hex[5] = {0};
int_to_hex(buf[0], hex);
int_to_hex(buf[1], hex + 2);
hex[4] = '\0';
printf("lux_task output: %s\n", hex);
}
extern "C" void lux_task(void *pvParameters) { extern "C" void lux_task(void *pvParameters) {
gpio_enable(signal_led_pin, GPIO_OUTPUT); gpio_enable(signal_led_pin, GPIO_OUTPUT);
gpio_enable(cs0, GPIO_OUTPUT); gpio_enable(cs0, GPIO_OUTPUT);
gpio_enable(gpio4, GPIO_OUTPUT); gpio_enable(nint_pin, GPIO_INPUT);
gpio_enable(gpio5, GPIO_OUTPUT); gpio_enable(init_pin, GPIO_OUTPUT);
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1); spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1);
gpio_set_interrupt(nint_pin, int_type, gpio_intr_handler);
uint8_t charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; uint8_t charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
uint8_t cnt = 0; uint8_t cnt = 0;
while(1) { while(1) {
uint8_t buf[2]; uint8_t out[2];
spi_transfer_8(1, charset[cnt++]); out[1] = 0x0F;
for(volatile int i = 0; i < 100; i++); out[0] = charset[cnt++];
spi_read(1, 0x00, buf, 2, SPI_8BIT); spi_transfer_16(1, *(uint16_t*)out);
char hex[5] = {0};
int_to_hex(buf[0], hex);
int_to_hex(buf[1], hex + 2);
hex[4] = '\0';
printf("lux_task output: %s\n", hex);
vTaskDelay(1000/portTICK_PERIOD_MS); vTaskDelay(2000/portTICK_PERIOD_MS);
cnt %= sizeof(charset); cnt %= sizeof(charset);
} }