123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- /*
- * (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;
- }
|