164 行
3.3 KiB
C
164 行
3.3 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"
|
|
#include "pot.h"
|
|
#include "settings.h"
|
|
#include "drums.h"
|
|
#include "drone.h"
|
|
#include "uart.h"
|
|
#include "timer.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();
|
|
settings_load();
|
|
printf("Console on USART2 Enabled.\r\n");
|
|
printf("\r\n=====================\r\n");
|
|
printf("Entering bootlevel 0.\r\n");
|
|
led_setup();
|
|
led_on(0);
|
|
printf("System clock started.\r\n");
|
|
button_init();
|
|
//pin_exti_init();
|
|
printf("Buttons initialized.\r\n");
|
|
}
|
|
|
|
|
|
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("Initializing digital-potmeters\r\n");
|
|
pot_init();
|
|
|
|
printf("Initializing DAC...\r\n");
|
|
dac_init();
|
|
|
|
printf("Activating I2C bus...\r\n");
|
|
i2c1_setup();
|
|
i2c_display_init();
|
|
printf("Display initialized.\r\n");
|
|
printf("Displaying splash screen...\r\n");
|
|
ui_init();
|
|
printf("UI initialized.\r\n");
|
|
timer_init();
|
|
drums_init();
|
|
drone_init();
|
|
drums_start();
|
|
|
|
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)
|
|
{
|
|
static uint32_t last_b_time = 0;
|
|
if (jiffies - last_b_time < 100)
|
|
return;
|
|
last_b_time = jiffies;
|
|
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;
|
|
char uc;
|
|
volatile uint32_t poll_time = 0;
|
|
uint32_t bstatus = 0;
|
|
|
|
const uint32_t hb_len = 20;
|
|
const uint32_t hb_pulse = 5;
|
|
|
|
bootlevel_0();
|
|
bootlevel_1();
|
|
//pin_exti_start_read();
|
|
|
|
while(1) {
|
|
hb = 1;
|
|
led_on(LED);
|
|
poll_time = jiffies;
|
|
|
|
timer_poll();
|
|
|
|
if (!keepalive_callback)
|
|
ui_keepalive(hb_len);
|
|
else
|
|
keepalive_callback();
|
|
|
|
|
|
do {
|
|
WFI();
|
|
ret = button_poll(process_button);
|
|
uc = uart_read();
|
|
if (uc)
|
|
process_button(uc, 0);
|
|
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;
|
|
}
|