93 lines
2.1 KiB
C
93 lines
2.1 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "driver/gpio.h"
|
|
#include "drivers/fonts.h"
|
|
#include "drivers/i2c.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
#include "drivers/battery.h"
|
|
#include "drivers/pins.h"
|
|
|
|
#include "drivers/bmi270.h"
|
|
#include "drivers/es8311.h"
|
|
#include "drivers/i2s.h"
|
|
#include "drivers/irled.h"
|
|
#include "drivers/sdcard.h"
|
|
#include "drivers/st7789.h"
|
|
#include "drivers/tca8418.h"
|
|
#include "drivers/ws2812.h"
|
|
#include "hal/gpio_types.h"
|
|
#include "projdefs.h"
|
|
|
|
void app_main(void) {
|
|
printf("boot\n");
|
|
set_pin_dirs();
|
|
battery_start_task();
|
|
i2c_init(BUS_I2C_SDA, BUS_I2C_SCL);
|
|
|
|
ws2812_init();
|
|
es8311_init();
|
|
tca8418_init();
|
|
if (!bmi270_init()) {
|
|
printf("BMI Init failed\n");
|
|
}
|
|
ir_pwm_init();
|
|
ir_carrier_off();
|
|
|
|
initSD();
|
|
st7789_init();
|
|
printf("init done");
|
|
|
|
ws2812_send_rgb(255, 255, 255);
|
|
|
|
/*
|
|
static int16_t micbuf[512];
|
|
|
|
audio_read(micbuf, 512);
|
|
|
|
audio_write(micbuf, 512);
|
|
|
|
|
|
*/
|
|
|
|
while (1) {
|
|
|
|
// keyboard
|
|
uint8_t key;
|
|
uint8_t pressed;
|
|
|
|
char buf[256];
|
|
st7789_fill_rect(1, 1, LCD_WIDTH - 2, LCD_HEIGHT - 2, 0x0000);
|
|
st7789_draw_string(10, 10, "CARDPUTER TEST", 0xFFFF, 0x0000, false,
|
|
font5x7);
|
|
while (tca8418_read(&key, &pressed)) {
|
|
|
|
snprintf(buf, sizeof(buf), "key=%c %s %d %s", getKeyboardChar(key),
|
|
getKeyboardKeyName(key), key, pressed ? "pressed" : "released");
|
|
printf("%s\n", buf);
|
|
|
|
st7789_draw_string(30, 30, buf, 0x07E0, 0x0000, true, fontHitachi);
|
|
audio_beep();
|
|
}
|
|
|
|
bmi270_data_t bmiData;
|
|
|
|
if (!bmi270_read(&bmiData)) {
|
|
printf("BMI read failed\n");
|
|
} else {
|
|
|
|
snprintf(buf, sizeof(buf), "acc %f %f %f\ngyro %f %f %f\n", bmiData.ax,
|
|
bmiData.ay, bmiData.az, bmiData.gx, bmiData.gy, bmiData.gz);
|
|
st7789_draw_string(30, 60, buf, 0x07E0, 0x0000, true, fontHitachi);
|
|
}
|
|
|
|
snprintf(buf, sizeof(buf), "BAT: %d%%(%.3fV)", getBatteryPercentage(),
|
|
getBatteryVoltage());
|
|
st7789_draw_string(150, 10, buf, 0x07E0, 0x0000, true, fontHitachi);
|
|
st7789_flush();
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(20)); // 50 fps max
|
|
}
|
|
} |