From f6b959086671fb1bf8b2003d5c5384c7311a7735 Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 16 Apr 2019 23:38:46 +0900 Subject: center/fw: rename --- fw/main.c | 201 -------------------------------------------------------------- 1 file changed, 201 deletions(-) delete mode 100644 fw/main.c (limited to 'fw/main.c') diff --git a/fw/main.c b/fw/main.c deleted file mode 100644 index 2340ecb..0000000 --- a/fw/main.c +++ /dev/null @@ -1,201 +0,0 @@ -/* Megumin LED display firmware - * Copyright (C) 2018 Sebastian Götte - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "global.h" - -#include "adc.h" - -volatile unsigned int sys_time = 0; -volatile unsigned int sys_time_seconds = 0; - -void TIM1_BRK_UP_TRG_COM_Handler() { - TIM1->SR &= ~TIM_SR_UIF_Msk; -} - -enum packet_type { - PKT_TYPE_RESERVED = 0, - PKT_TYPE_SET_OUTPUTS_BINARY = 1, - PKT_TYPE_SET_GLOBAL_BRIGHTNESS = 2, - PKT_TYPE_SET_OUTPUTS = 3, - PKT_TYPE_MAX -}; - -struct { - struct command_if_def cmd_if; - int payload_len[PKT_TYPE_MAX]; -} cmd_if = {{.packet_type_max=PKT_TYPE_MAX}, { - [PKT_TYPE_RESERVED] = 0, - [PKT_TYPE_SET_OUTPUTS_BINARY] = 1, - [PKT_TYPE_SET_GLOBAL_BRIGHTNESS] = 1, - [PKT_TYPE_SET_OUTPUTS] = 8 } -}; - -void set_drv_gpios(uint8_t val) { - int a=!!(val&1), b=!!(val&2), c=!!(val&4), d=!!(val&8); - GPIOA->ODR &= ~(!a<<3 | !b<<7 | c<<6 | d<<4); - GPIOA->ODR |= a<<3 | b<<7 | !c<<6 | !d<<4; -} - -uint8_t out_state = 0x01; -void set_outputs(uint8_t val[8]) { - /* TODO implement BCM for digital brightness control */ - int x = 0; - for (int i=0; i<8; i++) - if (val[i] > 127) - x |= 1<> 4); -} - -void TIM3_IRQHandler(void) { - GPIOA->BSRR = 1<<10; - if (TIM3->SR & TIM_SR_UIF) - unblank_low(); - else - blank(); - - TIM3->SR = 0; - GPIOA->BRR = 1<<10; -} - -void handle_command(int command, uint8_t *args) { - static int global_brightness = 0xff; - switch (command) { - case PKT_TYPE_SET_OUTPUTS_BINARY: - set_outputs_binary(args[0], global_brightness); - break; - - case PKT_TYPE_SET_GLOBAL_BRIGHTNESS: - global_brightness = args[0]; - break; - - case PKT_TYPE_SET_OUTPUTS: - set_outputs(args); - break; - } -} - -int main(void) { - RCC->CR |= RCC_CR_HSEON; - while (!(RCC->CR&RCC_CR_HSERDY)); - RCC->CFGR &= ~RCC_CFGR_PLLMUL_Msk & ~RCC_CFGR_SW_Msk & ~RCC_CFGR_PPRE_Msk & ~RCC_CFGR_HPRE_Msk; - RCC->CFGR |= ((6-2)< 48.0MHz */ - RCC->CR |= RCC_CR_PLLON; - while (!(RCC->CR&RCC_CR_PLLRDY)); - RCC->CFGR |= (2<AHBENR |= RCC_AHBENR_DMAEN | RCC_AHBENR_GPIOAEN | RCC_AHBENR_FLITFEN; - RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN | RCC_APB2ENR_ADCEN| RCC_APB2ENR_DBGMCUEN | RCC_APB2ENR_TIM1EN | RCC_APB2ENR_TIM1EN;; - RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; - - /* TIM3 foo */ - TIM3->CCMR2 = (6<CCER = TIM_CCER_CC4E; /* Enable capture/compare unit 4 connected to ADC */ - - TIM3->PSC = 48-1; - TIM3->CCR4 = 170-1; - TIM3->ARR = 200-1; - - TIM3->DIER |= TIM_DIER_UIE | TIM_DIER_CC4IE; - - TIM3->CR1 |= TIM_CR1_CEN; - NVIC_EnableIRQ(TIM3_IRQn); - NVIC_SetPriority(TIM3_IRQn, 3<<5); - - GPIOA->MODER |= - (0<OSPEEDR |= - (2<IDR & (1<<0); - if (new != bit) { - bit = new; - TIM3->EGR |= TIM_EGR_UG; - unblank_low(); - } - /* idle */ - } -} - -void NMI_Handler(void) { - asm volatile ("bkpt"); -} - -void HardFault_Handler(void) __attribute__((naked)); -void HardFault_Handler() { - asm volatile ("bkpt"); -} - -void SVC_Handler(void) { - asm volatile ("bkpt"); -} - - -void PendSV_Handler(void) { - asm volatile ("bkpt"); -} - -void SysTick_Handler(void) { - static int n = 0; - sys_time++; - if (n++ == 1000) { - n = 0; - sys_time_seconds++; - } -} - -- cgit