fiatlux/firmware/lux.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

2021-07-02 16:45:29 +00:00
//
// Created by jedi on 25.06.21.
//
2021-07-19 20:31:30 +00:00
#include "lux.h"
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
#include <esp/spi.h>
const int signal_led_pin = 2;
const int cs0 = 15;
const int gpio4 = 4;
const int gpio5 = 5;
extern "C" void signal_led(bool state) {
gpio_write(signal_led_pin, !state);
2021-07-19 20:31:30 +00:00
}
2022-05-29 21:47:30 +00:00
void int_to_hex(uint8_t i, char buf[2]) {
uint8_t hex_charset[] = "0123456789ABCDEF";
buf[0] = hex_charset[i >> 4];
buf[1] = hex_charset[i & 0x0F];
}
2021-07-19 20:31:30 +00:00
extern "C" void lux_task(void *pvParameters) {
gpio_enable(signal_led_pin, GPIO_OUTPUT);
gpio_enable(cs0, GPIO_OUTPUT);
gpio_enable(gpio4, GPIO_OUTPUT);
gpio_enable(gpio5, GPIO_OUTPUT);
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1);
2022-05-29 20:12:44 +00:00
uint8_t charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
2022-05-28 03:43:51 +00:00
uint8_t cnt = 0;
while(1) {
2022-05-29 21:47:30 +00:00
uint8_t buf[2];
2022-05-29 20:53:48 +00:00
spi_transfer_8(1, charset[cnt++]);
2022-05-29 20:42:25 +00:00
for(volatile int i = 0; i < 100; i++);
2022-05-29 21:47:30 +00:00
spi_read(1, 0x00, buf, 2, 1);
char hex[5];
int_to_hex(buf[0], hex);
int_to_hex(buf[1], hex + 2);
hex[4] = '\0';
printf("lux_task output: %s\n", hex);
2022-05-28 03:43:51 +00:00
2022-05-28 06:18:30 +00:00
vTaskDelay(1000/portTICK_PERIOD_MS);
2022-05-29 20:12:44 +00:00
cnt %= sizeof(charset);
2022-05-28 03:43:51 +00:00
}
2022-05-29 21:47:30 +00:00
2021-07-19 20:31:30 +00:00
vTaskDelete(nullptr);
}