templature_fan/Source/User/demo/inc/demo.h

130 lines
3.5 KiB
C
Raw Normal View History

2024-07-23 13:17:52 +00:00
#ifndef DEMO_H
#define DEMO_H
#include "type_define.h"
#include <board_cfg.h>
#include "hk32f030m.h"
#include "stdio.h"
/*----------------------------------------------------------------
IIC Configuration
*/
#define SOFT_IIC_ENABLED 1
#if (SOFT_IIC_ENABLED)
void IIC_SF_Init(void);
u8 IIC_SF_Send_Byte(u8 ord, u8 data);
u8 IIC_SF_Send(u8 ord, u8 *data, u32 len);
#endif
#define HW_IIC_ENABLED 0
/*----------------------------------------------------------------
SPI Configuration
*/
#define SPI_HW_ENABLED 1
#if (SPI_HW_ENABLED)
u8 SPI_HW_Send(u8 chr);
u8 SPI_HW_Transfer(u8 chr, u8 *data);
void SPI_HW_Init(void);
#endif
/*----------------------------------------------------------------
ST7735S Configuration
*/
#define ST7735S_ENABLED 1
#define ST7735S_SHOW_ASC16 1
#if(SPI_HW_ENABLED==0)
#error("ST7735 Ҫ<><D2AA><EFBFBD><EFBFBD>spi")
#endif
#if ST7735S_ENABLED
void LCD_Init(void);
#if ST7735S_SHOW_ASC16
void LCD_ShowChar16(u32 x,u32 y,u8 chr,u16 bkcolor,u16 color);
u8 LCD_ShowString(u8 *chr,u16 bkcolor,u16 color);
u8 LCD_SetCharPos(u32 x,u32 y);
void LCD_ShowPic(u8 *pic, u16 bkcolor, u16 color);
#endif
#endif
/*----------------------------------------------------------------
Flash Configuration
*/
u16 Flash_ReadID(void);
u8 Flash_Init(void);
/*----------------------------------------------------------------
uart configuration
*/
void USART_Config(void);
/*----------------------------------------------------------------
GPIO interface
*/
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HAL_GPIO_Init(GPIOA, GPIO_Pin_1,GPIO_Mode_OUT,GPIO_PuPd_NOPULL,GPIO_OType_PP)
* <EFBFBD><EFBFBD>©<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: HAL_GPIO_Init(GPIOA, GPIO_Pin_1,GPIO_Mode_OUT,GPIO_PuPd_NOPULL,GPIO_OType_OD)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HAL_GPIO_Init(GPIOA, GPIO_Pin_1,GPIO_Mode_IN,GPIO_PuPd_UP,GPIO_OType_OD)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HAL_GPIO_Init(GPIOA, GPIO_Pin_1,GPIO_Mode_IN,GPIO_PuPd_DOWN,GPIO_OType_OD)
*/
void HAL_GPIO_Init(GPIO_TypeDef *port, u32 pin, u32 mode, u32 pull, u32 type);
// GPIO output
// port:GPIOA-GPIOD,pin:GPIO_Pin_0-GPIO_Pin_7
#define GPIO_OUT_H(port, pin) \
{ \
port->BSRR = pin; \
};
// port:GPIOA-GPIOD,pin:GPIO_Pin_0-GPIO_Pin_7
#define GPIO_OUT_L(port, pin) \
{ \
port->BRR = pin; \
};
// port:GPIOA-GPIOD,pin:GPIO_Pin_0-GPIO_Pin_7
#define GPIO_OUT_TOGGLE(port, pin) \
{ \
port->ODR ^= pin; \
}
// GPIO pull up and down
// port:GPIOA-GPIOD,pin:0-7
#define GPIO_PULL_UP(port, pin) \
{ \
port->PUPDR = 1 << (pin * 2) | port->PUPDR; \
}
// port:GPIOA-GPIOD,pin:0-7
#define GPIO_PULL_DOWN(port, pin) \
{ \
port->PUPDR = 2 << (pin * 2) | port->PUPDR; \
}
// port:GPIOA-GPIOD,pin:0-7
#define GPIO_PULL_NULL(port, pin) \
{ \
port->PUPDR = 0 << (pin * 2) | port->PUPDR; \
}
// port:GPIOA-GPIOD,pin:0-7
#define GPIO_READ(port, pin) ((port->IDR >> pin) & 1)
void EEPROM_WriteByte(uint32_t offset, uint8_t data_in);
void EERPOM_ReadByte(uint32_t offset,uint8_t *data_out);
/*----------------------------------------------------------------
Bit
*/
#define Bit15 0x8000
#define Bit14 0x4000
#define Bit13 0x2000
#define Bit12 0x1000
#define Bit11 0x800
#define Bit10 0x400
#define Bit9 0x200
#define Bit8 0x100
#define Bit7 0x80
#define Bit6 0x40
#define Bit5 0x20
#define Bit4 0x10
#define Bit3 0x08
#define Bit2 0x04
#define Bit1 0x02
#define Bit0 0x01
#endif