solo1/targets/stm32l432/src/main.c

108 wiersze
2.4 KiB
C
Czysty Zwykły widok Historia

2019-02-12 22:18:17 +00:00
// Copyright 2019 SoloKeys Developers
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
2018-10-17 04:32:32 +00:00
#include <stdint.h>
2018-10-20 21:13:44 +00:00
#include <stdio.h>
2018-10-21 01:02:59 +00:00
#include <string.h>
2018-10-17 04:32:32 +00:00
#include "stm32l4xx.h"
#include "stm32l4xx_ll_gpio.h"
#include "stm32l4xx_ll_rcc.h"
#include "stm32l4xx_ll_system.h"
#include "stm32l4xx_ll_pwr.h"
#include "stm32l4xx_ll_utils.h"
#include "stm32l4xx_ll_cortex.h"
#include "stm32l4xx_ll_gpio.h"
#include "stm32l4xx_ll_usart.h"
#include "stm32l4xx_ll_bus.h"
#include "stm32l4xx_ll_usb.h"
#include "stm32l4xx_hal_pcd.h"
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_hid.h"
/*#include "usbd_hid.h"*/
2018-10-20 21:13:44 +00:00
2018-12-01 19:42:49 +00:00
#include APP_CONFIG
2018-10-21 01:02:59 +00:00
#include "flash.h"
2018-10-21 16:01:36 +00:00
#include "rng.h"
2018-10-21 17:14:59 +00:00
#include "led.h"
#include "device.h"
#include "util.h"
#include "fifo.h"
2018-10-28 20:30:55 +00:00
#include "log.h"
2018-10-17 04:32:32 +00:00
2018-10-26 01:25:49 +00:00
#ifdef TEST_SOLO_STM32
2018-10-17 04:32:32 +00:00
#define Error_Handler() _Error_Handler(__FILE__,__LINE__)
2018-10-28 20:30:55 +00:00
#define PAGE_SIZE 2048
#define PAGES 128
// Pages 119-127 are data
#define COUNTER2_PAGE (PAGES - 4)
#define COUNTER1_PAGE (PAGES - 3)
#define STATE2_PAGE (PAGES - 2)
#define STATE1_PAGE (PAGES - 1)
2018-11-08 00:39:02 +00:00
uint32_t __90_ms = 0;
#define IS_BUTTON_PRESSED() (0 == (LL_GPIO_ReadInputPort(SOLO_BUTTON_PORT) & SOLO_BUTTON_PIN))
2018-10-28 20:30:55 +00:00
2018-11-08 00:39:02 +00:00
// Timer6 overflow handler. happens every ~90ms.
void TIM6_DAC_IRQHandler()
{
// timer is only 16 bits, so roll it over here
TIM6->SR = 0;
__90_ms += 1;
2018-10-28 20:30:55 +00:00
}
2018-10-17 04:32:32 +00:00
2018-11-08 00:39:02 +00:00
uint32_t millis()
2018-10-17 04:32:32 +00:00
{
2018-11-08 00:39:02 +00:00
return (((uint32_t)TIM6->CNT) + (__90_ms * 90));
}
void _Error_Handler(char *file, int line)
{
while(1)
{
}
2018-11-04 22:12:27 +00:00
}
int main(void)
{
uint32_t i = 5;
hw_init();
2018-11-04 22:12:27 +00:00
LL_GPIO_SetPinMode(SOLO_BUTTON_PORT,SOLO_BUTTON_PIN,LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(SOLO_BUTTON_PORT,SOLO_BUTTON_PIN,LL_GPIO_PULL_UP);
flash_option_bytes_init(1);
2018-10-20 21:13:44 +00:00
while (1)
{
2018-11-04 22:12:27 +00:00
uint32_t t0 = millis() % 750;
if (! IS_BUTTON_PRESSED())
{
2018-11-04 22:12:27 +00:00
if (t0 < 750*1/3)
{
led_rgb(0 | (0 << 8) | (i << 17));
}
else if (t0 < 750*2/3)
{
led_rgb(0 | (i << 8) | (0 << 16));
}
else
{
led_rgb(i | (0 << 8) | (0 << 16));
}
}
2018-11-04 22:12:27 +00:00
else
{
2018-11-04 22:12:27 +00:00
led_rgb(0x151515);
}
2018-10-17 04:32:32 +00:00
}
}
2018-10-26 01:25:49 +00:00
#endif