# HG changeset patch # User Ethan Zonca # Date 2014-07-10 23:02:21 # Node ID 7476de768f19e182e095b1da15f790fc7337dd2d # Parent 63171fecb213f879d613bd21dbb045f9c3eb9f01 Refactor of oled driver diff --git a/libraries/oleddrv/bsp.h b/libraries/oleddrv/bsp.h --- a/libraries/oleddrv/bsp.h +++ b/libraries/oleddrv/bsp.h @@ -58,8 +58,8 @@ D1/Data 3 4 D0/Clk #define MMA_WAKEUP() GPIOB->BSRR = GPIO_Pin_11 #define Is_MMA_WAKEUP() (GPIOB->ODR & GPIO_Pin_11) -#define DMA_SSD_1303 DMA1_Channel5 -#define DMA_Handler_SSD_1303 DMA1_Channel5_IRQHandler +#define DMA_SSD_1306 DMA1_Channel5 +#define DMA_Handler_SSD_1306 DMA1_Channel5_IRQHandler #define Is_Enc_Key_Down() (!(GPIOA->IDR & GPIO_Pin_0)) diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -10,15 +10,14 @@ static __IO uint32_t TimingDelay; void init_gpio(); void init_spi(); -/* Main */ int main(void) { - // Hopefully init clocks + // Init clocks SystemInit(); RCC_ClocksTypeDef RCC_Clocks; - //SysTick end of count event each 1ms + // SysTick end of count event each 1ms RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); @@ -28,7 +27,7 @@ int main(void) init_gpio(); init_spi(); - //SSD1302_Init(); + //ssd1306_Init(); //SSD1303_DrawPoint(3,3,1); //SSD1303_DrawPoint(5,5,0); @@ -38,16 +37,8 @@ int main(void) while(1) { - /* Turn on LD0 Blue LED during 1s each time User button is pressed */ - //STM_EVAL_LEDOn(LED4); GPIO_SetBits(LED_POWER); - //STM_EVAL_LEDOn(LED3); - - /* wait for 1s */ Delay(150); - - /* Turn off LD4 Blue LED after 1s each time User button is pressed */ - //STM_EVAL_LEDOff(LED4); GPIO_ResetBits(LED_POWER); Delay(150); } @@ -61,7 +52,6 @@ int main(void) void Delay(__IO uint32_t nTime) { TimingDelay = nTime; - while(TimingDelay != 0); } @@ -80,7 +70,8 @@ void TimingDelay_Decrement(void) -void init_spi(void) { +void init_spi(void) +{ SPI_InitTypeDef SPI_InitStructure; // OLED IC @@ -114,17 +105,6 @@ void init_gpio(void) { GPIO_InitTypeDef GPIO_InitStruct; - /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - */ - - /*Enable or disable the APB peripheral clock */ - - // Enable SPI clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); @@ -132,6 +112,7 @@ void init_gpio(void) { // Enable GPIO clocks RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA, ENABLE); + // Enable DMA clocks (Is AHB even the right thing???) RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // EMZ TODO get the right ones /*Configure GPIO pin : PC */ diff --git a/ssd1306.c b/ssd1306.c --- a/ssd1306.c +++ b/ssd1306.c @@ -1,10 +1,10 @@ /******************************************************************************* -* File Name : SSD1303.c +* File Name : ssd1306.c * Author : lxyppc * Version : V1.0 * Date : 10-01-21 -* Description : SSD1303 operations -* the SSH1101A is compatible with SSD1303 +* Description : ssd1306 operations +* the SSH1101A is compatible with ssd1306 *******************************************************************************/ /* Includes ------------------------------------------------------------------*/ @@ -15,18 +15,18 @@ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ -#define SSD1303_PAGE_NUMBER 8 -#define SSD1303_COLUMN_NUMBER 128 -#define SSD1303_COLUMN_MARGIN_START 2 -#define SSD1303_COLUMN_MARGIN_END 2 -#define SSD1303_X_PIXEL 128 -#define SSD1303_Y_PIXEL 64 +#define SSD1306_PAGE_NUMBER 8 +#define SSD1306_COLUMN_NUMBER 128 +#define SSD1306_COLUMN_MARGIN_START 2 +#define SSD1306_COLUMN_MARGIN_END 2 +#define SSD1306_X_PIXEL 128 +#define SSD1306_Y_PIXEL 64 /* Private macro -------------------------------------------------------------*/ -#define SSD1303_Buffer (_SSD1303_Buffer + SSD1303_COLUMN_MARGIN_START) +#define ssd1306_Buffer (_SSD1306_Buffer + SSD1306_COLUMN_MARGIN_START) /* Private variables ---------------------------------------------------------*/ -static uint8_t _SSD1303_Buffer[SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER + SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END] = {0}; +static uint8_t _SSD1306_Buffer[SSD1306_COLUMN_NUMBER*SSD1306_PAGE_NUMBER + SSD1306_COLUMN_MARGIN_START + SSD1306_COLUMN_MARGIN_END] = {0}; static uint8_t pageIndex = 0; static uint8_t iS_SSD_On = 0; static uint8_t pre_on = 0; @@ -37,15 +37,15 @@ static uint8_t lastContrast = 0xCC; void WriteCommand(unsigned char command); void WriteData(unsigned char data); void OnPageTransferDone(void); -unsigned long SSD1303_OFF(void); -unsigned long SSD1303_ON(void); -unsigned char* SSD1303_GetBuffer() +unsigned long ssd1306_OFF(void); +unsigned long ssd1306_ON(void); +unsigned char* ssd1306_GetBuffer() { - return SSD1303_Buffer; + return ssd1306_Buffer; } /******************************************************************************* * Function Name : WriteCommand -* Description : Write command to the SSD1303 +* Description : Write command to the ssd1306 * Input : None * Output : None * Return : None @@ -59,7 +59,7 @@ void WriteCommand(unsigned char command) /******************************************************************************* * Function Name : WriteData -* Description : Write data to the SSD1303 +* Description : Write data to the ssd1306 * Input : None * Output : None * Return : None @@ -72,13 +72,13 @@ void WriteData(unsigned char data) } /******************************************************************************* -* Function Name : SSD1303_Init -* Description : Initialize the SSD1303 +* Function Name : ssd1306_Init +* Description : Initialize the ssd1306 * Input : None * Output : None * Return : None *******************************************************************************/ -void SSD1303_Init(void) +void ssd1306_Init(void) { /* Generate a reset */ @@ -88,7 +88,7 @@ void SSD1303_Init(void) SSD_Reset_High(); /************************************************* - // SSD1303 Initialization Command + // ssd1306 Initialization Command *************************************************/ // Lower Column Address WriteCommand(0x00); /* Set Lower Column Address */ @@ -155,7 +155,7 @@ void SSD1303_Init(void) WriteCommand(0x10); /* Turn on the controller */ - pre_on = SSD1303_ON(); + pre_on = ssd1306_ON(); // // Set Charge pump // WriteCommand(0x8D); /* Set Charge pump */ // WriteCommand(0x14); /* 0x14=ON, 0x10=Off */ @@ -165,70 +165,70 @@ void SSD1303_Init(void) } /******************************************************************************* -* Function Name : SSD1303_TurnOff -* Description : Turn off the SSD1303 controller +* Function Name : ssd1306_TurnOff +* Description : Turn off the ssd1306 controller * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned long SSD1303_TurnOff(void) +unsigned long ssd1306_TurnOff(void) { pre_on = 0; return iS_SSD_On; } /******************************************************************************* -* Function Name : SSD1303_TurnOn -* Description : Turn off the SSD1303 controller +* Function Name : ssd1306_TurnOn +* Description : Turn off the ssd1306 controller * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned long SSD1303_TurnOn(void) +unsigned long ssd1306_TurnOn(void) { pre_on = 1; return iS_SSD_On; } /******************************************************************************* -* Function Name : SSD1303_SetContrast -* Description : Set the SSD1303 contrast +* Function Name : ssd1306_SetContrast +* Description : Set the ssd1306 contrast * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned char SSD1303_SetContrast(unsigned char contrast) +unsigned char ssd1306_SetContrast(unsigned char contrast) { curContrast = contrast; return lastContrast; } /******************************************************************************* -* Function Name : SSD1303_GetContrast -* Description : Get the SSD1303 contrast +* Function Name : ssd1306_GetContrast +* Description : Get the ssd1306 contrast * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned char SSD1303_GetContrast() +unsigned char ssd1306_GetContrast() { return lastContrast; } /******************************************************************************* -* Function Name : SSD1303_OFF -* Description : Turn off the SSD1303 controller +* Function Name : ssd1306_OFF +* Description : Turn off the ssd1306 controller * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned long SSD1303_OFF(void) +unsigned long ssd1306_OFF(void) { if(iS_SSD_On){ #ifdef DEBUG_UI uint32_t i = 0; - for(i=0;iCCR &= ((uint32_t)0xFFFFFFFE); - DMA1_Channel5->CNDTR = SSD1303_COLUMN_NUMBER+SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END; - DMA1_Channel5->CMAR = (uint32_t)(SSD1303_Buffer+SSD1303_COLUMN_NUMBER*pageIndex - SSD1303_COLUMN_MARGIN_START); - DMA_SSD_1303->CCR |= ((uint32_t)0x00000001); + DMA1_Channel5->CNDTR = ssd1306_COLUMN_NUMBER+SSD1306_COLUMN_MARGIN_START + SSD1306_COLUMN_MARGIN_END; + DMA1_Channel5->CMAR = (uint32_t)(ssd1306_Buffer+SSD1306_COLUMN_NUMBER*pageIndex - SSD1306_COLUMN_MARGIN_START); + DMA_SSD_1306->CCR |= ((uint32_t)0x00000001); pageIndex++; #else SSD_A0_High(); - DMA_SSD_1303->CCR &= ((uint32_t)0xFFFFFFFE); - DMA_SSD_1303->CNDTR = SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER;//+SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END; - DMA_SSD_1303->CMAR = (uint32_t)(SSD1303_Buffer);//+SSD1303_COLUMN_NUMBER*pageIndex); - //DMA_Cmd(DMA_SSD_1303, ENABLE); - DMA_SSD_1303->CCR |= ((uint32_t)0x00000001); + DMA_SSD_1306->CCR &= ((uint32_t)0xFFFFFFFE); + DMA_SSD_1306->CNDTR = SSD1306_COLUMN_NUMBER*SSD1306_PAGE_NUMBER;//+SSD1306_COLUMN_MARGIN_START + SSD1306_COLUMN_MARGIN_END; + DMA_SSD_1306->CMAR = (uint32_t)(ssd1306_Buffer);//+SSD1306_COLUMN_NUMBER*pageIndex); + //DMA_Cmd(DMA_SSD_1306, ENABLE); + DMA_SSD_1306->CCR |= ((uint32_t)0x00000001); // pageIndex++; - pageIndex = SSD1303_PAGE_NUMBER; + pageIndex = SSD1306_PAGE_NUMBER; #endif } @@ -327,7 +327,7 @@ void OnPageTransferDone(void) * Output : None * Return : None *******************************************************************************/ -void DMA_Handler_SSD_1303(void) //DMA1_Channel5_IRQHandler(void) +void DMA_Handler_SSD_1306(void) //DMA1_Channel5_IRQHandler(void) { if(DMA_GetITStatus(DMA1_IT_TC5)){ DMA_ClearITPendingBit(DMA1_IT_GL5); @@ -347,11 +347,11 @@ void StartPageTransfer(void) pageIndex = 0; if(pre_on){ if(iS_SSD_On == 0){ - pre_on = SSD1303_ON(); + pre_on = ssd1306_ON(); } }else{ if(iS_SSD_On){ - pre_on = SSD1303_OFF(); + pre_on = ssd1306_OFF(); } } if( curContrast != lastContrast ){ @@ -369,24 +369,24 @@ void StartPageTransfer(void) Display related functions ******************************************************************************/ /******************************************************************************* -* Function Name : SSD1303_DrawBlock -* Description : Draw a block with specify data to SSD1303 +* Function Name : ssd1306_DrawBlock +* Description : Draw a block with specify data to ssd1306 * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned long SSD1303_DrawBlock( +unsigned long ssd1306_DrawBlock( Pos_t x, Pos_t y, Pos_t cx, Pos_t cy, const unsigned char* data) { - if(x >= SSD1303_X_PIXEL)return 0; - if(y >= SSD1303_Y_PIXEL)return 0; - if(x+cx > SSD1303_X_PIXEL ) cx = SSD1303_X_PIXEL - x ; - if(y+cy > SSD1303_Y_PIXEL ) cy = SSD1303_Y_PIXEL - y ; - unsigned char* pStart = SSD1303_Buffer + (y/8)*SSD1303_COLUMN_NUMBER + x; + if(x >= SSD1306_X_PIXEL)return 0; + if(y >= SSD1306_Y_PIXEL)return 0; + if(x+cx > SSD1306_X_PIXEL ) cx = SSD1306_X_PIXEL - x ; + if(y+cy > SSD1306_Y_PIXEL ) cy = SSD1306_Y_PIXEL - y ; + unsigned char* pStart = ssd1306_Buffer + (y/8)*SSD1306_COLUMN_NUMBER + x; unsigned char offset1 = y%8; unsigned char offset2 = (cy+y)%8; if(data){ @@ -400,13 +400,13 @@ unsigned long SSD1303_DrawBlock( unsigned short tmp = *pStart & mask1; for(;j>=8; } if(offset2){ tmp |= ((((unsigned short)data[j*cx])<>=8; // if(j == (cy/8)-1){ // // Last line -// *(pStart + (j+1)*SSD1303_COLUMN_NUMBER + i + x) &= ~mask; -// *(pStart + (j+1)*SSD1303_COLUMN_NUMBER + i + x) |= tmp; +// *(pStart + (j+1)*ssd1306_COLUMN_NUMBER + i + x) &= ~mask; +// *(pStart + (j+1)*ssd1306_COLUMN_NUMBER + i + x) |= tmp; // } // } // } @@ -471,20 +471,20 @@ unsigned long SSD1303_DrawBlock( } /******************************************************************************* -* Function Name : SSD1303_DrawPoint -* Description : Draw a point with specify data to SSD1303 +* Function Name : ssd1306_DrawPoint +* Description : Draw a point with specify data to ssd1306 * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned long SSD1303_DrawPoint( +unsigned long ssd1306_DrawPoint( Pos_t x, Pos_t y, Color_t color) { - if(x >= SSD1303_X_PIXEL)return 0; - if(y >= SSD1303_Y_PIXEL)return 0; - unsigned char* pStart = SSD1303_Buffer + (y/8)*SSD1303_COLUMN_NUMBER + x; + if(x >= SSD1306_X_PIXEL)return 0; + if(y >= SSD1306_Y_PIXEL)return 0; + unsigned char* pStart = ssd1306_Buffer + (y/8)*SSD1306_COLUMN_NUMBER + x; unsigned char mask = 1<<(y%8); if(color){ *pStart |= mask; @@ -495,41 +495,41 @@ unsigned long SSD1303_DrawPoint( } /******************************************************************************* -* Function Name : SSD1303_ReadPoint -* Description : Read a point from SSD1303 +* Function Name : ssd1306_ReadPoint +* Description : Read a point from ssd1306 * Input : None * Output : None * Return : None *******************************************************************************/ -unsigned long SSD1303_ReadPoint( +unsigned long ssd1306_ReadPoint( Pos_t x, Pos_t y) { - unsigned char* pStart = SSD1303_Buffer + (y/8)*SSD1303_COLUMN_NUMBER + x; + unsigned char* pStart = ssd1306_Buffer + (y/8)*SSD1306_COLUMN_NUMBER + x; unsigned char mask = 1<<(y%8); return *pStart&mask ? 1 : 0; } /******************************************************************************* -* Function Name : SSD1303_ClearScreen +* Function Name : ssd1306_ClearScreen * Description : Clear the screen contents * Input : None * Output : None * Return : None *******************************************************************************/ -void SSD1303_FillScreen(Color_t color) +void ssd1306_FillScreen(Color_t color) { unsigned char mask = color ? 0xFF : 0; unsigned long i = 0; - for(i=0;i