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,169 @@
|
||||
/*!
|
||||
* @file apm32f10x_int.c
|
||||
*
|
||||
* @brief Main Interrupt Service Routines
|
||||
*
|
||||
* @version V1.0.2
|
||||
*
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @attention
|
||||
*
|
||||
* Copyright (C) 2020-2022 Geehy Semiconductor
|
||||
*
|
||||
* You may not use this file except in compliance with the
|
||||
* GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
|
||||
*
|
||||
* The program is only for reference, which is distributed in the hope
|
||||
* that it will be usefull and instructional for customers to develop
|
||||
* their software. Unless required by applicable law or agreed to in
|
||||
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
|
||||
* and limitations under the License.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "apm32f10x_int.h"
|
||||
#include "systick.h"
|
||||
|
||||
/** @addtogroup Peripherals_Library Standard Peripheral Library
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @addtogroup INT_Driver INT Driver
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @addtogroup INT_Fuctions Fuctions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @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)
|
||||
{
|
||||
delay_decrement();
|
||||
}
|
||||
|
||||
/**@} end of group INT_Fuctions*/
|
||||
/**@} end of group INT_Driver*/
|
||||
/**@} end of group Peripherals_Library*/
|
||||
@@ -0,0 +1,91 @@
|
||||
/*---------------------------------------
|
||||
- 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 "apm32f10x_gpio.h"
|
||||
#include "apm32f10x_rcm.h"
|
||||
#include "apm32f10x_usart.h"
|
||||
|
||||
void board_usart_init(void)
|
||||
{
|
||||
GPIO_Config_T GPIO_ConfigStruct;
|
||||
USART_Config_T USART_ConfigStruct;
|
||||
|
||||
RCM_EnableAPB2PeriphClock((RCM_APB2_PERIPH_T)(RCM_APB2_PERIPH_GPIOA | RCM_APB2_PERIPH_USART1));
|
||||
|
||||
GPIO_ConfigStruct.mode = GPIO_MODE_AF_PP;
|
||||
GPIO_ConfigStruct.pin = GPIO_PIN_9;
|
||||
GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
|
||||
GPIO_Config(GPIOA, &GPIO_ConfigStruct);
|
||||
|
||||
USART_ConfigStruct.baudRate = 115200;
|
||||
USART_ConfigStruct.hardwareFlow = USART_HARDWARE_FLOW_NONE;
|
||||
USART_ConfigStruct.mode = USART_MODE_TX;
|
||||
USART_ConfigStruct.parity = USART_PARITY_NONE;
|
||||
USART_ConfigStruct.stopBits = USART_STOP_BIT_1;
|
||||
USART_ConfigStruct.wordLength = USART_WORD_LEN_8B;
|
||||
USART_Config(USART1, &USART_ConfigStruct);
|
||||
|
||||
USART_Enable(USART1);
|
||||
}
|
||||
|
||||
/* retarget the C library printf function to the USART */
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
USART_TxData(USART1, (uint8_t)ch);
|
||||
while (RESET == USART_ReadStatusFlag(USART1, USART_FLAG_TXBE))
|
||||
;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
void board_led_init(void)
|
||||
{
|
||||
GPIO_Config_T configStruct;
|
||||
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOB);
|
||||
|
||||
configStruct.pin = GPIO_PIN_2;
|
||||
configStruct.mode = GPIO_MODE_OUT_PP;
|
||||
configStruct.speed = GPIO_SPEED_50MHz;
|
||||
GPIO_Config(GPIOB, &configStruct);
|
||||
}
|
||||
|
||||
void board_led_on(void)
|
||||
{
|
||||
GPIO_WriteBitValue(GPIOB, GPIO_PIN_2, BIT_SET);
|
||||
}
|
||||
|
||||
void board_led_off(void)
|
||||
{
|
||||
GPIO_WriteBitValue(GPIOB, GPIO_PIN_2, BIT_RESET);
|
||||
}
|
||||
|
||||
void board_led_toggle(void)
|
||||
{
|
||||
GPIOB->ODATA ^= GPIO_PIN_2;
|
||||
}
|
||||
|
||||
void board_button_init(void)
|
||||
{
|
||||
GPIO_Config_T configStruct;
|
||||
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOA);
|
||||
|
||||
configStruct.pin = GPIO_PIN_0;
|
||||
configStruct.mode = GPIO_MODE_IN_PD;
|
||||
configStruct.speed = GPIO_SPEED_50MHz;
|
||||
GPIO_Config(GPIOA, &configStruct);
|
||||
}
|
||||
|
||||
uint8_t board_button_state_get(void)
|
||||
{
|
||||
if(GPIO_ReadInputBit(GPIOA, GPIO_PIN_0) == BIT_RESET)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*---------------------------------------
|
||||
- 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 "main.h"
|
||||
#include "board.h"
|
||||
#include "systick.h"
|
||||
|
||||
#include "epaper.h"
|
||||
#include "bmp.h"
|
||||
|
||||
#define EPD_BWR
|
||||
|
||||
uint8_t image_bw[4000];
|
||||
#ifdef EPD_BWR
|
||||
uint8_t image_red[4000];
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Main program
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @retval None
|
||||
*
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
uint8_t text[20];
|
||||
|
||||
systick_config();
|
||||
|
||||
board_led_init();
|
||||
board_button_init();
|
||||
board_usart_init();
|
||||
|
||||
printf("\r\nWeAct Studio Core Board\r\n");
|
||||
printf("weactstudio.taobao.com\r\n");
|
||||
printf("weactstudio.aliexpress.com\r\n");
|
||||
printf("wwww.weact-tc.cn\r\n\r\n");
|
||||
printf("SystemClk:%d\r\n", SystemCoreClock);
|
||||
printf("Epaper Module Test\r\n");
|
||||
|
||||
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(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 *)&"APM32F103CBT6 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(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 *)&"APM32F103CBT6 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)
|
||||
{
|
||||
if (!board_button_state_get())
|
||||
{
|
||||
delay(100);
|
||||
board_led_toggle();
|
||||
}
|
||||
else
|
||||
{
|
||||
board_led_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*---------------------------------------
|
||||
- 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 "systick.h"
|
||||
#include "apm32f10x.h"
|
||||
#include "apm32f10x_pmu.h"
|
||||
|
||||
volatile uint32_t _tick = 0;
|
||||
|
||||
/*!
|
||||
\brief configure systick
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void systick_config(void)
|
||||
{
|
||||
/* setup systick timer for (SysTick_Freq) Hz interrupts */
|
||||
if (SysTick_Config(SystemCoreClock / SysTick_Freq))
|
||||
{
|
||||
/* capture error */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
/* configure the systick handler priority */
|
||||
NVIC_SetPriority(SysTick_IRQn, 0x05U);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay a time in milliseconds
|
||||
\param[in] count: count in milliseconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void delay(uint32_t count)
|
||||
{
|
||||
uint32_t utick;
|
||||
utick = count + systick_get_tick();
|
||||
|
||||
while (systick_get_tick() < utick)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay a time in milliseconds with low power
|
||||
\param[in] count: count in milliseconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void delay_lp(uint32_t count)
|
||||
{
|
||||
uint32_t utick;
|
||||
utick = count + systick_get_tick();
|
||||
|
||||
while (systick_get_tick() < utick)
|
||||
{
|
||||
PMU_EnterSTANDBYMode();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay decrement
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void delay_decrement(void)
|
||||
{
|
||||
_tick++;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief get systick tick
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
|
||||
uint32_t systick_get_tick(void)
|
||||
{
|
||||
return _tick;
|
||||
}
|
||||
|
||||
void systick_DisableIRQ(void)
|
||||
{
|
||||
/* Disable SysTick Interrupt */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void systick_EnableIRQ(void)
|
||||
{
|
||||
/* Enable SysTick Interrupt */
|
||||
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void systick_Disable(void)
|
||||
{
|
||||
/* Disable SysTick */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
void systick_Enable(void)
|
||||
{
|
||||
/* Enable SysTick */
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
void systick_deinit(void)
|
||||
{
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user