mirror of
https://github.com/WeActStudio/WeActStudio.EpaperModule.git
synced 2026-08-16 13:13:45 +02:00
first commit
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f403a_407_clock.c
|
||||
* @version v2.0.9
|
||||
* @date 2022-04-25
|
||||
* @brief system clock config program
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* includes ------------------------------------------------------------------*/
|
||||
#include "at32f403a_407_clock.h"
|
||||
|
||||
/** @addtogroup AT32F403A_periph_template
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup 403A_System_clock_configuration System_clock_configuration
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief system clock config program
|
||||
* @note the system clock is configured as follow:
|
||||
* - system clock = hext / 2 * pll_mult
|
||||
* - system clock source = pll (hext)
|
||||
* - hext = 8000000
|
||||
* - sclk = 240000000
|
||||
* - ahbdiv = 1
|
||||
* - ahbclk = 240000000
|
||||
* - apb2div = 2
|
||||
* - apb2clk = 120000000
|
||||
* - apb1div = 2
|
||||
* - apb1clk = 120000000
|
||||
* - pll_mult = 60
|
||||
* - pll_range = GT72MHZ (greater than 72 mhz)
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void system_clock_config(void)
|
||||
{
|
||||
/* reset crm */
|
||||
crm_reset();
|
||||
|
||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
|
||||
|
||||
/* wait till hext is ready */
|
||||
while(crm_hext_stable_wait() == ERROR)
|
||||
{
|
||||
}
|
||||
|
||||
/* config pll clock resource */
|
||||
crm_pll_config(CRM_PLL_SOURCE_HEXT_DIV, CRM_PLL_MULT_60, CRM_PLL_OUTPUT_RANGE_GT72MHZ);
|
||||
|
||||
/* config hext division */
|
||||
crm_hext_clock_div_set(CRM_HEXT_DIV_2);
|
||||
|
||||
/* enable pll */
|
||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
||||
|
||||
/* wait till pll is ready */
|
||||
while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET)
|
||||
{
|
||||
}
|
||||
|
||||
/* config ahbclk */
|
||||
crm_ahb_div_set(CRM_AHB_DIV_1);
|
||||
|
||||
/* config apb2clk */
|
||||
crm_apb2_div_set(CRM_APB2_DIV_2);
|
||||
|
||||
/* config apb1clk */
|
||||
crm_apb1_div_set(CRM_APB1_DIV_2);
|
||||
|
||||
/* enable auto step mode */
|
||||
crm_auto_step_mode_enable(TRUE);
|
||||
|
||||
/* select pll as system clock source */
|
||||
crm_sysclk_switch(CRM_SCLK_PLL);
|
||||
|
||||
/* wait till pll is used as system clock source */
|
||||
while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL)
|
||||
{
|
||||
}
|
||||
|
||||
/* disable auto step mode */
|
||||
crm_auto_step_mode_enable(FALSE);
|
||||
|
||||
/* update system_core_clock global variable */
|
||||
system_core_clock_update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file at32f403a_407_int.c
|
||||
* @version v2.0.9
|
||||
* @date 2022-04-25
|
||||
* @brief main interrupt service routines.
|
||||
**************************************************************************
|
||||
* Copyright notice & Disclaimer
|
||||
*
|
||||
* The software Board Support Package (BSP) that is made available to
|
||||
* download from Artery official website is the copyrighted work of Artery.
|
||||
* Artery authorizes customers to use, copy, and distribute the BSP
|
||||
* software and its related documentation for the purpose of design and
|
||||
* development in conjunction with Artery microcontrollers. Use of the
|
||||
* software is governed by this copyright notice and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
|
||||
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
|
||||
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
|
||||
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
|
||||
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
/* includes ------------------------------------------------------------------*/
|
||||
#include "at32f403a_407_int.h"
|
||||
|
||||
/** @addtogroup AT32F403A_periph_template
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup 403A_LED_toggle
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief this function handles nmi exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles hard fault exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* go to infinite loop when hard fault exception occurs */
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles memory manage exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* go to infinite loop when memory manage exception occurs */
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles bus fault exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* go to infinite loop when bus fault exception occurs */
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles usage fault exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* go to infinite loop when usage fault exception occurs */
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles svcall exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles debug monitor exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles pendsv_handler exception.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief this function handles systick handler.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,127 @@
|
||||
/*---------------------------------------
|
||||
- WeAct Studio Official Link
|
||||
- taobao: weactstudio.taobao.com
|
||||
- aliexpress: weactstudio.aliexpress.com
|
||||
- github: github.com/WeActTC
|
||||
- gitee: gitee.com/WeAct-TC
|
||||
- blog: www.weact-tc.cn
|
||||
---------------------------------------*/
|
||||
|
||||
#include "board.h"
|
||||
#include "delay.h"
|
||||
|
||||
uint8_t g_speed = FAST;
|
||||
|
||||
void led_init(void)
|
||||
{
|
||||
gpio_init_type gpio_init_struct;
|
||||
|
||||
/* enable the led clock */
|
||||
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
||||
|
||||
/* set default parameter */
|
||||
gpio_default_para_init(&gpio_init_struct);
|
||||
|
||||
/* configure the led gpio */
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_13;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||
gpio_init(GPIOC, &gpio_init_struct);
|
||||
}
|
||||
|
||||
void led_toggle(void)
|
||||
{
|
||||
GPIOC->odt ^= GPIO_PINS_13;
|
||||
}
|
||||
|
||||
void led_set(confirm_state bit_state)
|
||||
{
|
||||
gpio_bits_write(GPIOC, GPIO_PINS_13, bit_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief configure button gpio
|
||||
* @param button: specifies the button to be configured.
|
||||
* @retval none
|
||||
*/
|
||||
void button_init(void)
|
||||
{
|
||||
gpio_init_type gpio_init_struct;
|
||||
|
||||
/* enable the button clock */
|
||||
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
||||
|
||||
/* set default parameter */
|
||||
gpio_default_para_init(&gpio_init_struct);
|
||||
|
||||
/* configure button pin as input with pull-up/pull-down */
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||
gpio_init_struct.gpio_pins = GPIO_PINS_0;
|
||||
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
|
||||
gpio_init(GPIOA, &gpio_init_struct);
|
||||
}
|
||||
|
||||
flag_status button_getstate(void)
|
||||
{
|
||||
return gpio_input_data_bit_read(GPIOA, GPIO_PINS_0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief configure button exint
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void button_exint_init(void)
|
||||
{
|
||||
exint_init_type exint_init_struct;
|
||||
|
||||
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
|
||||
gpio_exint_line_config(GPIO_PORT_SOURCE_GPIOA, GPIO_PINS_SOURCE0);
|
||||
|
||||
exint_default_para_init(&exint_init_struct);
|
||||
exint_init_struct.line_enable = TRUE;
|
||||
exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT;
|
||||
exint_init_struct.line_select = EXINT_LINE_0;
|
||||
exint_init_struct.line_polarity = EXINT_TRIGGER_FALLING_EDGE;
|
||||
exint_init(&exint_init_struct);
|
||||
|
||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||
nvic_irq_enable(EXINT0_IRQn, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief button handler function
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void button_isr(void)
|
||||
{
|
||||
/* delay 5ms */
|
||||
delay_ms(5);
|
||||
|
||||
/* clear interrupt pending bit */
|
||||
exint_flag_clear(EXINT_LINE_0);
|
||||
|
||||
/* check input pin state */
|
||||
if (RESET == gpio_input_data_bit_read(GPIOA, GPIO_PINS_0))
|
||||
{
|
||||
if (g_speed == SLOW)
|
||||
g_speed = FAST;
|
||||
else
|
||||
g_speed = SLOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief exint0 interrupt handler
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void EXINT0_IRQHandler(void)
|
||||
{
|
||||
button_isr();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "delay.h"
|
||||
|
||||
/* delay macros */
|
||||
#define STEP_DELAY_MS 50
|
||||
|
||||
/* delay variable */
|
||||
static __IO uint32_t fac_us;
|
||||
static __IO uint32_t fac_ms;
|
||||
|
||||
/**
|
||||
* @brief initialize delay function
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
void delay_init(void)
|
||||
{
|
||||
/* configure systick */
|
||||
systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
|
||||
fac_us = system_core_clock / (1000000U);
|
||||
fac_ms = fac_us * (1000U);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief inserts a delay time.
|
||||
* @param nus: specifies the delay time length, in microsecond.
|
||||
* @retval none
|
||||
*/
|
||||
void delay_us(uint32_t nus)
|
||||
{
|
||||
uint32_t temp = 0;
|
||||
SysTick->LOAD = (uint32_t)(nus * fac_us);
|
||||
SysTick->VAL = 0x00;
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk ;
|
||||
do
|
||||
{
|
||||
temp = SysTick->CTRL;
|
||||
}while((temp & 0x01) && !(temp & (1 << 16)));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->VAL = 0x00;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief inserts a delay time.
|
||||
* @param nms: specifies the delay time length, in milliseconds.
|
||||
* @retval none
|
||||
*/
|
||||
void delay_ms(uint16_t nms)
|
||||
{
|
||||
uint32_t temp = 0;
|
||||
while(nms)
|
||||
{
|
||||
if(nms > STEP_DELAY_MS)
|
||||
{
|
||||
SysTick->LOAD = (uint32_t)(STEP_DELAY_MS * fac_ms);
|
||||
nms -= STEP_DELAY_MS;
|
||||
}
|
||||
else
|
||||
{
|
||||
SysTick->LOAD = (uint32_t)(nms * fac_ms);
|
||||
nms = 0;
|
||||
}
|
||||
SysTick->VAL = 0x00;
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
do
|
||||
{
|
||||
temp = SysTick->CTRL;
|
||||
}while((temp & 0x01) && !(temp & (1 << 16)));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->VAL = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief inserts a delay time.
|
||||
* @param sec: specifies the delay time, in seconds.
|
||||
* @retval none
|
||||
*/
|
||||
void delay_sec(uint16_t sec)
|
||||
{
|
||||
uint16_t index;
|
||||
for(index = 0; index < sec; index++)
|
||||
{
|
||||
delay_ms(500);
|
||||
delay_ms(500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*---------------------------------------
|
||||
- WeAct Studio Official Link
|
||||
- taobao: weactstudio.taobao.com
|
||||
- aliexpress: weactstudio.aliexpress.com
|
||||
- github: github.com/WeActTC
|
||||
- gitee: gitee.com/WeAct-TC
|
||||
- blog: www.weact-tc.cn
|
||||
---------------------------------------*/
|
||||
|
||||
#include "at32f403a_407_clock.h"
|
||||
|
||||
#include "delay.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "epaper.h"
|
||||
#include "bmp.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define EPD_BWR
|
||||
|
||||
uint8_t image_bw[4000];
|
||||
#ifdef EPD_BWR
|
||||
uint8_t image_red[4000];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief main function.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
uint8_t text[20];
|
||||
|
||||
system_clock_config();
|
||||
|
||||
delay_init();
|
||||
|
||||
button_init();
|
||||
button_exint_init();
|
||||
led_init();
|
||||
|
||||
epd_io_init();
|
||||
|
||||
epd_init();
|
||||
|
||||
#ifdef EPD_BWR
|
||||
epd_paint_newimage(image_bw,EPD_W,EPD_H,EPD_ROTATE_180,EPD_COLOR_WHITE);
|
||||
|
||||
epd_paint_newimage(image_red,EPD_W,EPD_H,EPD_ROTATE_180,EPD_COLOR_WHITE);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showPicture(0,0,250,122,gImage_2,EPD_COLOR_BLACK);
|
||||
|
||||
epd_paint_selectimage(image_red);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showPicture(0,0,250,122,gImage_3,EPD_COLOR_WHITE);
|
||||
|
||||
epd_display(image_bw,image_red);
|
||||
|
||||
delay_ms(8000);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showString(10,0,(uint8_t *)&"2.13 Epaper Module",EPD_FONT_SIZE24x12,EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10,29,(uint8_t *)&"Designed By WeAct Studio",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10,50,(uint8_t *)&"with 250 x 122 resolution",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
|
||||
|
||||
epd_paint_selectimage(image_red);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
|
||||
sprintf((char *)&text,">> Hello World.");
|
||||
epd_paint_showString(10,71,text,EPD_FONT_SIZE24x12,EPD_COLOR_RED);
|
||||
|
||||
#if 0
|
||||
epd_paint_showString(10,100,(uint8_t *)&"AT32F403ACGU7 Example",EPD_FONT_SIZE16x8,EPD_COLOR_RED);
|
||||
#else
|
||||
epd_paint_drawRectangle(10,103,240,116,EPD_COLOR_RED,1);
|
||||
#endif
|
||||
epd_display(image_bw,image_red);
|
||||
#else
|
||||
epd_paint_newimage(image_bw,EPD_W,EPD_H,EPD_ROTATE_180,EPD_COLOR_WHITE);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showPicture(0,0,250,122,gImage_1,EPD_COLOR_WHITE);
|
||||
|
||||
epd_displayBW(image_bw);
|
||||
|
||||
delay_ms(5000);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showString(10,0,(uint8_t *)&"2.13 Epaper Module",EPD_FONT_SIZE24x12,EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10,29,(uint8_t *)&"Designed By WeAct Studio",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10,50,(uint8_t *)&"with 250 x 122 resolution",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
|
||||
|
||||
sprintf((char *)&text,">> Hello World.");
|
||||
epd_paint_showString(10,71,text,EPD_FONT_SIZE24x12,EPD_COLOR_BLACK);
|
||||
|
||||
#if 0
|
||||
epd_paint_showString(10,100,(uint8_t *)&"AT32F403ACGU7 Example",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
|
||||
#else
|
||||
epd_paint_drawRectangle(10,103,240,116,EPD_COLOR_BLACK,1);
|
||||
#endif
|
||||
epd_displayBW(image_bw);
|
||||
#endif
|
||||
|
||||
epd_enter_deepsleepmode(EPD_DEEPSLEEP_MODE1);
|
||||
while (1)
|
||||
{
|
||||
led_toggle();
|
||||
delay_ms(g_speed * DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
Reference in New Issue
Block a user