gadget-tester/main.c
2019-11-22 11:12:54 +01:00

136 lines
2.8 KiB
C

/*
* (c) danielinux 2019
* GPLv.2
*
* See LICENSE for details
*/
#include <string.h>
#include <stdio.h>
#include "system.h"
#include "led.h"
#include "display.h"
#include "spi_flash.h"
#include "uart.h"
#include "systick.h"
#include "ui.h"
#include "button.h"
#include "adc.h"
extern uint32_t cpu_freq;
#define BLINK_INTERVAL 500
static int sdcard_detected = 0;
static void bootlevel_0(void)
{
clock_pll_on();
uart2_setup(115200, 8, 0, 1);
systick_enable();
WFI();
printf("Console on USART2 Enabled.\r\n");
printf("\r\n=====================\r\n");
printf("Entering bootlevel 0.\r\n");
//led_setup(LED);
//led_on(LED);
printf("System clock started.\r\n");
button_init();
//pin_exti_init();
printf("Buttons initialized.\r\n");
}
extern void timer_init(void);
static void bootlevel_1(void)
{
uint16_t spiflash_vendor;
int sdcard_present;
printf("=====================\r\n");
printf("Entering bootlevel 1.\r\n");
printf("Initializing ADC...\r\n");
adc_init();
printf("Activating I2C bus...\r\n");
i2c_display_init();
printf("Display initialized.\r\n");
printf("Displaying splash screen...\r\n");
ui_init();
printf("UI initialized.\r\n");
timer_init();
printf("System up and running.\r\n\n\n");
}
static void (*process_input_callback)(uint8_t press, int hold) = NULL;
static void (*keepalive_callback)(void) = NULL;
void set_input_callback(void (*cb)(uint8_t press, int hold))
{
process_input_callback = cb;
}
void clear_input_callback(void)
{
process_input_callback = NULL;
}
void set_keepalive(void (*cb)(void))
{
keepalive_callback = cb;
}
void clear_keepalive(void)
{
keepalive_callback = NULL;
}
void process_button(uint8_t press, int hold)
{
if (process_input_callback)
process_input_callback(press, hold);
else
ui_button_press(press, hold);
}
extern void gettime(uint32_t *s, uint32_t *us);
int main(void) {
int hb = 1;
int fs_on = 0;
int ret;
volatile uint32_t poll_time = 0;
uint32_t bstatus = 0;
const uint32_t hb_len = 400;
const uint32_t hb_pulse = 5;
bootlevel_0();
bootlevel_1();
//pin_exti_start_read();
while(1) {
hb = 1;
//led_on(LED);
poll_time = jiffies;
if (!keepalive_callback)
ui_keepalive(hb_len);
else
keepalive_callback();
do {
WFI();
ret = button_poll(process_button);
if (jiffies - poll_time > hb_pulse) {
if (hb) {
uint32_t s, us;
hb = 0;
//led_off(LED);
// gettime(&s, &us);
// printf("TIME: %u.%05u\r\n", s, us);
}
}
} while ((jiffies - poll_time) < hb_len);
}
return 0;
}