【Atmel SAM R21创意大赛周计划】+场景遥控增加OLED功能程序
[复制链接]
【Atmel SAM R21创意大赛周计划】+场景遥控增加OLED功能程序
1、硬件连接:OLED1 XPLAINED PRO板与SAMR21 XPLAINED PRO的EXT1接口对接
配置头文件中选择: #define BSP_SUPPORT BOARD_SAMR21_ZLLEK
2、管脚端口
#define LCD_SPI_CS_CONFIG PORT_B, 3u, 3u
#define LCD_CMDSEL_CONFIG PORT_A, 13u, 3u
#define LCD_RESET_CONFIG PORT_A, 23u, 3u
3、OLED初始化
/**************************************************************************//**
\brief Initialize the LCD
******************************************************************************/
void BSP_LcdInit(void)
{
PinConfig_t lcdResetPin = {LCD_RESET_CONFIG};//A23
PinConfig_t lcdCmdSelPin = {LCD_CMDSEL_CONFIG};//A13
PinConfig_t lcdSpiCSPin = {LCD_SPI_CS_CONFIG};//B03 WCJ
/* Initialize LCD Pins Other than SPI connected Pins */
GPIO_make_out(&lcdResetPin);
GPIO_make_out(&lcdCmdSelPin);
GPIO_make_out(&lcdSpiCSPin); //WCJ
/* Initialize SPI Interface */
lcdSpiDescriptor.tty = SPI_CHANNEL_1;// wcj
lcdSpiDescriptor.baudRate = SPI_CLOCK_RATE_1000;
lcdSpiDescriptor.clockMode = SPI_CLOCK_MODE0;
lcdSpiDescriptor.dataOrder = SPI_DATA_MSB_FIRST;
lcdSpiDescriptor.callback = NULL;
if (-1 == HAL_OpenSpi(&lcdSpiDescriptor))//调用BSP_BoardSpecificSpiPinInit(SpiChannel_t tty)
{
return;
}
GPIO_clr(&lcdResetPin);
GPIO_set(&lcdResetPin);
GPIO_clr(&lcdResetPin);
GPIO_clr(&lcdCmdSelPin);
GPIO_set(&lcdCmdSelPin);
GPIO_clr(&lcdCmdSelPin);
GPIO_clr(&lcdSpiCSPin);
GPIO_set(&lcdSpiCSPin);
GPIO_clr(&lcdSpiCSPin);
/* Reset LCD before Initialization*/
GPIO_clr(&lcdResetPin);
HAL_Delay(100);
GPIO_set(&lcdResetPin);
/* Multiplex ratio 1/32 Duty (0x0F~0x3F) */
lcdCommand(LCD_CMD_SET_MULTIPLEX_RATIO);
lcdCommand(0x1F);
/* Set Display Offset */
lcdCommand(LCD_CMD_SET_DISPLAY_OFFSET);
lcdCommand(0x00);
/* Set Display Start Line (0x00~0x3F) */
lcdCommand(LCD_CMD_SET_DISPLAY_START_LINE(0x00));
/* Set Column Address 0 Mapped to SEG0 */
lcdCommand(LCD_CMD_SET_SEGMENT_RE_MAP_COL127_SEG0);
/* Set COM/Row Scan Scan from COM63 to 0 */
lcdCommand(LCD_CMD_SET_COM_OUTPUT_SCAN_DOWN);
/* Set COM Pins hardware configuration */
lcdCommand(LCD_CMD_SET_COM_PINS);
lcdCommand(0x02);
/* Set Contrast Control */
lcdCommand(LCD_CMD_SET_CONTRAST_CONTROL_FOR_BANK0);
lcdCommand(0x7F);
/* Disable Entire display On */
lcdCommand(LCD_CMD_ENTIRE_DISPLAY_AND_GDDRAM_ON);
/* Set Normal Display */
lcdCommand(LCD_CMD_SET_NORMAL_DISPLAY);
/* Set Display Oscillator Frequency/Clock Divide Ratio */
lcdCommand(LCD_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO);
lcdCommand(0x80);
/* Enable charge pump regulator */
lcdCommand(LCD_CMD_SET_CHARGE_PUMP_SETTING);
lcdCommand(0x14);
/* Set Display On */
lcdCommand(LCD_CMD_SET_DISPLAY_ON);
BSP_LcdCls();
}
#endif // BSP_SUPPORT == BOARD_SAMR21_ZLLEK
4、修改SPI初始化
void BSP_BoardSpecificSpiPinInit(SpiChannel_t tty)
//OLED1 XPLAINED板
//PINMUX_PB23D_SERCOM5_PAD3:SPI_SCK
//PINMUX_PB22D_SERCOM5_PAD2:SPI_MOSI
tty->spiPinConfig[SPI_SCK_SIG].pinNum = 23; //SPI_SCK = PB23
tty->spiPinConfig[SPI_SCK_SIG].portNum = PORT_B;
tty->spiPinConfig[SPI_SCK_SIG].functionConfig = 3;
tty->spiPinConfig[SPI_MOSI_SIG].pinNum = 22; //SPI_MOSI = PB22
tty->spiPinConfig[SPI_MOSI_SIG].portNum = PORT_B;
tty->spiPinConfig[SPI_MOSI_SIG].functionConfig = 3;
tty->dopoConfig = 1; //数据手册 MOSI,SCK脚
tty->dipoConfig = 0;
总结:在系统中增加外设驱动要修改低层驱动部分!注意配置文件中的宏定义!
|