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,90 @@
|
||||
/*---------------------------------------
|
||||
- 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 <stdio.h>
|
||||
|
||||
void board_usart0_init(void)
|
||||
{
|
||||
/* enable GPIO clock */
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
|
||||
/* enable USART clock */
|
||||
rcu_periph_clock_enable(RCU_USART0);
|
||||
|
||||
/* connect port to USARTx_Tx */
|
||||
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
|
||||
|
||||
/* connect port to USARTx_Rx */
|
||||
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
|
||||
|
||||
/* USART configure */
|
||||
usart_deinit(USART0);
|
||||
usart_baudrate_set(USART0, 115200U);
|
||||
usart_word_length_set(USART0, USART_WL_8BIT);
|
||||
usart_stop_bit_set(USART0, USART_STB_1BIT);
|
||||
usart_parity_config(USART0, USART_PM_NONE);
|
||||
usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
|
||||
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
|
||||
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
|
||||
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
|
||||
usart_enable(USART0);
|
||||
}
|
||||
|
||||
/* retarget the C library printf function to the USART */
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
usart_data_transmit(USART0, (uint8_t)ch);
|
||||
while (RESET == usart_flag_get(USART0, USART_FLAG_TBE))
|
||||
;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
void board_led_init(void)
|
||||
{
|
||||
/* enable the led clock */
|
||||
rcu_periph_clock_enable(RCU_GPIOB);
|
||||
/* configure led GPIO port */
|
||||
gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
|
||||
|
||||
GPIO_BC(GPIOB) = GPIO_PIN_2;
|
||||
}
|
||||
|
||||
void board_led_on(void)
|
||||
{
|
||||
GPIO_BOP(GPIOB) = GPIO_PIN_2;
|
||||
}
|
||||
|
||||
void board_led_off(void)
|
||||
{
|
||||
GPIO_BC(GPIOB) = GPIO_PIN_2;
|
||||
}
|
||||
|
||||
void board_led_toggle(void)
|
||||
{
|
||||
gpio_bit_write(GPIOB, GPIO_PIN_2,
|
||||
(bit_status)(1 - gpio_input_bit_get(GPIOB, GPIO_PIN_2)));
|
||||
}
|
||||
|
||||
void board_button_init(void)
|
||||
{
|
||||
/* enable the button clock */
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
rcu_periph_clock_enable(RCU_AF);
|
||||
|
||||
/* configure button pin as input */
|
||||
gpio_init(GPIOA, GPIO_MODE_IPD, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
|
||||
}
|
||||
|
||||
uint8_t board_button_state_get(void)
|
||||
{
|
||||
return gpio_input_bit_get(GPIOA, GPIO_PIN_0);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*!
|
||||
\file gd32f10x_it.c
|
||||
\brief interrupt service routines
|
||||
|
||||
\version 2014-12-26, V1.0.0, firmware for GD32F10x
|
||||
\version 2017-06-20, V2.0.0, firmware for GD32F10x
|
||||
\version 2018-07-31, V2.1.0, firmware for GD32F10x
|
||||
\version 2020-09-30, V2.2.0, firmware for GD32F10x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2020, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "gd32f10x_it.h"
|
||||
#include "main.h"
|
||||
#include "systick.h"
|
||||
|
||||
/*!
|
||||
\brief this function handles NMI exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles HardFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* if Hard Fault exception occurs, go to infinite loop */
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles MemManage exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* if Memory Manage exception occurs, go to infinite loop */
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles BusFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* if Bus Fault exception occurs, go to infinite loop */
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles UsageFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* if Usage Fault exception occurs, go to infinite loop */
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles SVC exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles DebugMon exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles PendSV exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles SysTick exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
delay_decrement();
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*---------------------------------------
|
||||
- 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 "gd32f10x.h"
|
||||
#include "systick.h"
|
||||
#include <stdio.h>
|
||||
#include "main.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "epaper.h"
|
||||
#include "bmp.h"
|
||||
|
||||
// define for White Black Red Epaper Module
|
||||
#define EPD_BWR
|
||||
|
||||
uint8_t image_bw[4000];
|
||||
#ifdef EPD_BWR
|
||||
uint8_t image_red[4000];
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint8_t text[20];
|
||||
uint32_t tick;
|
||||
|
||||
/* configure systick */
|
||||
systick_config();
|
||||
|
||||
gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);
|
||||
|
||||
/* initilize the LEDs, USART and key */
|
||||
board_led_init();
|
||||
board_button_init();
|
||||
board_usart0_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("CK_AHB is %d\r\n", rcu_clock_freq_get(CK_AHB));
|
||||
printf("CK_APB1 is %d\r\n", rcu_clock_freq_get(CK_APB1));
|
||||
printf("CK_APB2 is %d\r\n", rcu_clock_freq_get(CK_APB2));
|
||||
|
||||
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 *)&"GD32F103CBT6 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 *)&"GD32F103CBT6 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);
|
||||
|
||||
tick = systick_get_tick();
|
||||
while (1)
|
||||
{
|
||||
if (tick <= systick_get_tick())
|
||||
{
|
||||
tick += 100;
|
||||
if (!board_button_state_get())
|
||||
{
|
||||
board_led_toggle();
|
||||
}
|
||||
else
|
||||
{
|
||||
board_led_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*---------------------------------------
|
||||
- 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 "gd32f10x.h"
|
||||
#include "systick.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_to_sleepmode(WFI_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\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