123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #include "board.h"
- #define RUN_LED_PORT GPIOB
- #define RUN_LED_PIN PIN4
- //运行状态灯的定时器
- sw_timer_t run_status_timer;
- unsigned long run_led_speed = 500000;
- /**
- * 初始化运行灯的IO口
- *
- * @author lxz
- */
- static void hw_run_status_init(void) {
- //使能时钟
- rcu_periph_clock_enable(rcu_periph_clock_bit(RUN_LED_PORT));
- //配置IO为输出
- gpio_mode_set(RUN_LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, RUN_LED_PIN);
- gpio_output_options_set(RUN_LED_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RUN_LED_PIN);
- hw_run_status_on();
- sw_timer_start(&run_status_timer, 1, 0);
- }
- /**
- * 初始化Boot脚
- *
- * @author Lim (2023/3/15)
- *
- * @param void
- */
- void hw_boot_key_init(void) {
- #if USING_BOOT_KEY
- //使能时钟
- rcu_periph_clock_enable(rcu_periph_clock_bit(BOOT_KEY_PORT));
- //配置IO为输出
- gpio_mode_set(BOOT_KEY_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, BOOT_KEY_PIN);
- gpio_output_options_set(BOOT_KEY_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BOOT_KEY_PIN);
- #else
- return;
- #endif
- }
- /**
- * 初始化并读取按键状态
- *
- * @author Lim (2023/3/15)
- *
- * @return int
- */
- int hw_boot_key_read(void) {
- #if USING_BOOT_KEY
- volatile uint32_t i = 200000;
- //使能时钟
- rcu_periph_clock_enable(rcu_periph_clock_bit(BOOT_KEY_PORT));
- //配置IO为输出
- gpio_mode_set(BOOT_KEY_PORT, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, BOOT_KEY_PIN);
- gpio_output_options_set(BOOT_KEY_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BOOT_KEY_PIN);
- while (i-- > 0);
- return ((GPIO_ISTAT(BOOT_KEY_PORT) & BOOT_KEY_PIN) == BOOT_KEY_LEVEL);
- #else
- return 0;
- #endif
- }
- /**
- * 控制板初始化
- *
- * @author lxz
- *
- * @param void
- */
- void hw_board_init(void) {
- //Sys_Clock_Init(HW_BOART_CORE_FREQ, HW_BOART_MAIN_FREQ, HW_BOART_CORE_FREQ);
- Sys_NVIC_Set_VectorTable(0x08000000, 0x0);
- //hw_delay_init(HW_BOART_CORE_FREQ);
- sw_timer_init(HW_BOART_CORE_FREQ);
- hw_spi_init();
- //hw_spi_flash_attach(0,0);
- //hw_power_off_init();
- hw_io_pin_init();
- hw_run_status_init();
- hw_dma_uart_init(HW_BOART_CORE_FREQ);
- //hw_pwm_init(HW_BOART_CORE_FREQ);
- //hw_encoder_init();
- INTX_ENABLE();
- }
- /**
- * 进入节点模式,立刻切断所有的输出,全部为输入模式
- *
- * @author lxz (2019/5/30/鍛ㄥ洓)
- */
- void hw_board_enter_powerless(void) {
- hw_run_status_init();
- }
- /**
- * 强制灭灯
- *
- * @author LXZ (121219)
- *
- * @param void
- */
- void hw_run_status_off(void) {
- GPIO_BOP(RUN_LED_PORT) = RUN_LED_PIN;
- }
- /**
- * 强制亮灯
- *
- * @author LXZ (121219)
- *
- * @param void
- */
- void hw_run_status_on(void) {
- GPIO_BOP(RUN_LED_PORT) = (RUN_LED_PIN) << 16;
- }
- /**
- * 显示用于运行等指示的状态
- *
- * @author lxz
- *
- * @param void
- */
- void hw_run_status_show(void)
- {
- if (sw_timer_expire(&run_status_timer))
- {
- GPIO_TG(RUN_LED_PORT) = RUN_LED_PIN;
- sw_timer_start(&run_status_timer, 0, run_led_speed);
- }
- }
- /**
- * 初始化看门狗,看门狗需要注册中断函数
- *
- * @author LXZ (121219)
- *
- * @param void
- */
- void wathcdog_init(void (*func)()) {
- }
- /**
- * 喂狗
- *
- * @author LXZ (121219)
- *
- * @param void
- */
- void watchdog_kick(void) {
- }
- //临时保存数据参数,由于是放在了非初始化,允许保存app参数给Bootloader调用
- static int hw_noinit_data[16]__attribute__((section(".noinit")));
- /**
- * 写入保存参数
- *
- * @author lxz
- *
- * @param no
- * @param value
- */
- void hw_noinit_write(int no, int value) {
- hw_noinit_data[no] = value;
- }
- /**
- * 读取临时保存参数
- *
- * @author lxz
- *
- * @param no
- *
- * @return int
- */
- int hw_noinit_read(int no) {
- return hw_noinit_data[no];
- }
- /**
- * 硬件复位
- *
- * @author LXZ (051820)
- *
- * @param void
- */
- void hw_board_reboot(void) {
- Sys_Soft_Reset();
- }
|