Changeset - c5a349beceeb
[Not reviewed]
default
0 4 1
Ethan Zonca - 10 years ago 2014-08-18 22:35:31
ez@ethanzonca.com
OLED display now works, randomly writes the letter H now.
5 files changed with 719 insertions and 54 deletions:
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
#include "main.h"
 
#include "stm32l100c_discovery.h"
 
#include "ssd1306.h"
 
 
// USB includes
 
#include "hw_config.h"
 
#include "usb_lib.h"
 
#include "usb_desc.h"
 
#include "usb_pwr.h"
 
 
#define LED_POWER GPIOB,GPIO_Pin_9
 
#define LED_STAT  GPIOA,GPIO_Pin_15
 
 
#define MAX_CS GPIOB,GPIO_Pin_12
 
 
// TODO: Grab buttonpresses with interrupts
 
#define SW_BTN  GPIOB, GPIO_Pin_3
 
#define SW_UP   GPIOB, GPIO_Pin_7
 
#define SW_DOWN GPIOB, GPIO_Pin_6
 
#define SW_LEFT GPIOB, GPIO_Pin_5
 
#define SW_RIGHT GPIOB, GPIO_Pin_4
 
 
/* Extern variables ----------------------------------------------------------*/
 
// USB Supporting Vars
 
extern __IO uint8_t Receive_Buffer[64];
 
extern __IO  uint32_t Receive_length ;
 
extern __IO  uint32_t length ;
 
uint8_t Send_Buffer[64];
 
uint32_t packet_sent=1;
 
uint32_t packet_receive=1;
 
 
 
static __IO uint32_t TimingDelay;
 
 
// Move to header file
 
void init_gpio();
 
void init_spi();
 
void process();
 
void machine();
 
 
int main(void)
 
{
 
 
    // Init clocks
 
    SystemInit();
 
 
    init_gpio();
 
 
    Set_USBClock();
 
    USB_Interrupts_Config();
 
    USB_Init();
 
    // Init USB
 
    //Set_USBClock();
 
    //USB_Interrupts_Config();
 
    //USB_Init();
 
 
    GPIO_SetBits(LED_POWER);
 
    USB_Init(); // freezes here... maybe clock issue?
 
 
    RCC_ClocksTypeDef RCC_Clocks;
 
 
    // SysTick end of count event each 1ms
 
    RCC_GetClocksFreq(&RCC_Clocks);
 
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
 
 
    GPIO_ResetBits(LED_STAT);
 
    Delay(100);
 
    GPIO_SetBits(LED_POWER);
 
    Delay(500);
 
    GPIO_ResetBits(LED_POWER);
 
 
    init_spi();
 
 
    ssd1306_Init();
 
 
    ssd1306_DrawPoint(0,0,1);
 
    ssd1306_DrawPoint(0,1,1);
 
    ssd1306_DrawPoint(0,2,1);
 
    ssd1306_DrawPoint(0,3,1);
 
    ssd1306_DrawPoint(0,4,1);
 
    ssd1306_DrawPoint(0,5,1);
 
    ssd1306_DrawPoint(0,6,1);
 
 
    ssd1306_DrawPoint(1,3,1);
 
    ssd1306_DrawPoint(2,3,1);
 
    ssd1306_DrawPoint(3,3,1);
 
    ssd1306_DrawPoint(5,5,0);
 
    ssd1306_DrawPoint(4,3,1);
 
 
    ssd1306_DrawPoint(5,0,1);
 
    ssd1306_DrawPoint(5,1,1);
 
    ssd1306_DrawPoint(5,2,1);
 
    ssd1306_DrawPoint(5,3,1);
 
    ssd1306_DrawPoint(5,4,1);
 
    ssd1306_DrawPoint(5,5,1);
 
    ssd1306_DrawPoint(5,6,1);
 
 
 
    ssd1306_block_write();
 
 
    while(1)
 
   {  
 
        ssd1306_block_write();
 
        //ssd1306_block_write();
 
 
        // Process sensor inputs [TODO: 5hz?]
 
        process();
 
 
        // Run state machine [TODO: 50hz?]
 
        machine(); 
 
        // probably just passed the actual port
 
 
        // TODO: Grab buttonpresses with interrupts
 
        uint8_t sw_btn = GPIO_ReadInputDataBit(SW_BTN);
 
        uint8_t sw_up = GPIO_ReadInputDataBit(SW_UP);
 
        uint8_t sw_down = GPIO_ReadInputDataBit(SW_DOWN);
 
        uint8_t sw_left = GPIO_ReadInputDataBit(SW_LEFT);
 
        uint8_t sw_right = GPIO_ReadInputDataBit(SW_RIGHT);
 
 
//        SPI_I2S_SendData(SPI2,0xFA);
 
//        SPI_I2S_SendData(SPI1,0xFA);
 
 
        if(!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_3)) {
 
        if(!sw_btn) {
 
            GPIO_ToggleBits(LED_STAT);
 
            ssd1306_block_write();
 
        }
 
 
        GPIO_SetBits(LED_POWER);
 
        Delay(50);
 
        GPIO_ResetBits(LED_POWER);
 
        Delay(50);
 
    }
 
}
 
 
int32_t temp = 0;
 
int32_t setpoint = 0;
 
int32_t p = 1;
 
int32_t i = 1;
 
int32_t d = 1;
 
 
// Process things
 
void process()
 
{
 
    // Read MAX temp sensor
 
    GPIO_ResetBits(MAX_CS);
 
 
    // Assert CS
 
    // This may not clock at all... might need to send 16 bits first
 
    uint8_t retval = 0;//SPI_I2S_ReceiveData(SPI2);
 
 
    // Deassert CS
 
    GPIO_SetBits(MAX_CS);
 
 
    if((!retval || (temp & 0x2) != 0))
 
        return; // Comms error - this is happening right now
 
 
    if((temp & 0x4)!= 0)
 
        return; // Open thermocouple
 
 
 
    temp = (temp & 0x7FF8) >> 5;
 
 
 
    // TODO: Add calibration offset (linear)
 
 
 
    // Perform PID calculations
 
 
    // Write output to SSR
 
}
 
 
 
 
enum state {
 
    STATE_IDLE = 0,
 
    STATE_SETP,
 
    STATE_SETI,
 
    STATE_SETD,
 
 
    STATE_PREHEAT_BREW,
 
    STATE_MAINTAIN_BREW,
 
    STATE_PREHEAT_STEAM,
 
    STATE_MAINTAIN_STEAM,
 
};
 
 
 
uint8_t state = STATE_IDLE;
 
 
// State machine
 
void machine()
 
{
 
    
 
    switch(state)
 
    {
 
        // Idle state
 
        case STATE_IDLE:
 
        {
 
            // Write text to OLED
 
            // [ therm :: idle ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_SETP;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
        } break;
 
 
        case STATE_SETP:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set p ]
 
            // [ p = 12         ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
        case STATE_SETI:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set i ]
 
            // [ i = 12         ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
        case STATE_SETD:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set d ]
 
            // [ d = 12         ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
        case STATE_PREHEAT_BREW:
 
        {
 
            // Write text to OLED
 
            // [ therm : preheating brew ]
 
            // [ 30 => 120 C             ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            if(temp >= setpoint) {
 
                state = STATE_MAINTAIN_BREW;
 
            }
 
 
 
        } break;
 
 
        case STATE_MAINTAIN_BREW:
 
        {
 
            // Write text to OLED
 
            // [ therm : ready to brew ]
 
            // [ 30 => 120 C           ]
 
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
        case STATE_PREHEAT_STEAM:
 
        {
 
            // Write text to OLED
 
            // [ therm : preheating steam ]
 
            // [ 30 => 120 C           ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            if(temp >= setpoint) {
 
                state = STATE_MAINTAIN_STEAM;
 
            }
 
 
 
        } break;
 
 
        case STATE_MAINTAIN_STEAM:
 
        {
 
            // Write text to OLED
 
            // [ therm : ready to steam ]
 
            // [ 30 => 120 C            ]
 
 
            // Button handler
 
            if(GPIO_ReadInputDataBit(SW_BTN)) {
 
                state = STATE_IDLE;
 
            }
 
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 
 
 
        // Something is terribly wrong
 
        default:
 
        {
 
            state = STATE_IDLE;
 
 
        } break;
 
            
 
    }
 
}
 
 
 
/**
 
  * @brief  Inserts a delay time.
 
  * @param  nTime: specifies the delay time length, in 1 ms.
 
  * @retval None
 
  */
 
void Delay(__IO uint32_t nTime)
 
{
 
  TimingDelay = nTime;
 
  while(TimingDelay != 0);
 
}
 
 
 
/**
 
  * @brief  Decrements the TimingDelay variable.
 
  * @param  None
 
  * @retval None
 
  */
 
void TimingDelay_Decrement(void)
 
{
 
  if (TimingDelay != 0x00)
 
  { 
 
    TimingDelay--;
 
  }
 
}
 
 
 
void init_spi(void)
 
{
 
    SPI_InitTypeDef  SPI_InitStructure;
 
 
    // OLED IC
 
    SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
 
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
 
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
 
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
 
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
 
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
 
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
 
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
 
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
 
    SPI_InitStructure.SPI_CRCPolynomial = 7;
 
    SPI_Init(SPI1, &SPI_InitStructure);
 
    SPI_Cmd(SPI1, ENABLE);           /* Enable the SPI  */   
 
 
    // MAX IC
 
    //SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx;
 
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
 
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; // Andysworkshop
 
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // From andysworkshop
 
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; // same
 
    // Can be used for CS... SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
 
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
 
    //SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
 
    //SPI_InitStructure.SPI_CRCPolynomial = 7;
 
    SPI_Init(SPI2, &SPI_InitStructure);
 
    SPI_Cmd(SPI2, ENABLE);           /* Enable the SPI */
 
}
 
 
void init_gpio(void) {
 
 
 GPIO_InitTypeDef GPIO_InitStruct;
 
 
  // Enable SPI clocks
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
 
 
  // 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 */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
 
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_400KHz;
 
  GPIO_Init(GPIOC, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin : PB */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_10|GPIO_Pin_12 
 
                          |GPIO_Pin_9;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
 
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_400KHz;
 
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin : PA */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
 
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_400KHz;
 
  GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin : PB */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6 
 
                          |GPIO_Pin_7;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
 
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
  /** SPI1 GPIO Configuration  
 
  PA5   ------> SPI1_SCK
 
  PA7   ------> SPI1_MOSI
 
  */
 
 
  /*Enable or disable the AHB peripheral clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
 
  /*Configure GPIO pin : PA: MOSI,SCK */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
 
  GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin alternate function */
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
 
 
  /*Configure GPIO pin alternate function */
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);
 
 
  /** SPI2 GPIO Configuration  
 
  PB13   ------> SPI2_SCK
 
  PB14   ------> SPI2_MISO
 
  PB15   ------> SPI2_MOSI
 
  */
 
 
  /*Enable or disable the AHB peripheral clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
 
 
// SPI PINSSS
 
 
  /*Configure GPIO pin : PB, MOSI, SCK */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
 
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
// MISO
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14;
 
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
 
  GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
 
  /*Configure GPIO pin alternate function */
 
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
 
 
  /*Configure GPIO pin alternate function */
 
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
 
 
  /*Configure GPIO pin alternate function */
 
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
 
 
  /** USB GPIO Configuration  
 
  PA11   ------> USB_DM
 
  PA12   ------> USB_DP
 
  */
 
 
  /*Enable or disable the AHB peripheral clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
 
  /*Configure GPIO pin : PA */
 
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;
 
  GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_400KHz;
 
  GPIO_Init(GPIOA, &GPIO_InitStruct);
 
}
 
 
 
 
 
 
#ifdef  USE_FULL_ASSERT
 
 
/**
 
  * @brief  Reports the name of the source file and the source line number
 
  *   where the assert_param error has occurred.
 
  * @param  file: pointer to the source file name
 
  * @param  line: assert_param error line source number
 
  * @retval None
 
  */
 
void assert_failed(uint8_t* file, uint32_t line)
 
{ 
 
  /* User can add his own implementation to report the file name and line number,
 
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
 
  /* Infinite loop */
 
  while (1)
 
  {}
 
}
 
#endif
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
smallfonts.c
Show inline comments
 
new file 100644
 
/* Partially based on original code for the KS0108 by Stephane Rey */
 
/*
 
    @file     smallfonts.c
 
    @author   K. Townsend (microBuilder.eu)
 
    @date     22 March 2010
 
    @version  0.10
 

	
 
    @section LICENSE
 

	
 
    Software License Agreement (BSD License)
 

	
 
    Copyright (c) 2010, microBuilder SARL
 
    All rights reserved.
 

	
 
    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 holders 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 ''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 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 "nil.h"
 
#include "smallfonts.h"
 

	
 
/* Global variables */
 
const struct FONT_DEF Font_System3x6    = {3, 6, 32, 96,  au8FontSystem3x6};
 
const struct FONT_DEF Font_System5x8    = {5, 8, 32, 128, au8FontSystem5x8};
 
const struct FONT_DEF Font_System7x8    = {7, 8, 32, 128, au8FontSystem7x8};
 
const struct FONT_DEF Font_8x8          = {8, 8, 32, 128, au8Font8x8};
 
const struct FONT_DEF Font_8x8Thin      = {8, 8, 32, 128, au8Font8x8Thin};
 

	
 
/* System 3x6 - UPPER CASE ONLY */
 
const uint8_t au8FontSystem3x6[]= {
 
    0x00,0x00,0x00, /* Space */         
 
    0x00,0x5C,0x00, /* ! */                         
 
    0x0C,0x00,0x0C, /* " */                         
 
    0x7C,0x28,0x7C, /* # */                         
 
    0x7C,0x44,0x7C, /* 0x */                        
 
    0x24,0x10,0x48, /* % */                         
 
    0x28,0x54,0x08, /* & */                         
 
    0x00,0x0C,0x00, /* ' */                         
 
    0x38,0x44,0x00, /* ( */                         
 
    0x44,0x38,0x00, /* ) */                         
 
    0x20,0x10,0x08, /* // */                        
 
    0x10,0x38,0x10, /* + */                         
 
    0x80,0x40,0x00, /* , */                         
 
    0x10,0x10,0x10, /* - */                         
 
    0x00,0x40,0x00, /* . */                         
 
    0x20,0x10,0x08, /* / */    
 
    0x38,0x44,0x38, /* 0 */                     
 
    0x00,0x7C,0x00, /* 1 */                         
 
    0x64,0x54,0x48, /* 2 */                         
 
    0x44,0x54,0x28, /* 3 */                         
 
    0x1C,0x10,0x7C, /* 4 */                         
 
    0x4C,0x54,0x24, /* 5 */                         
 
    0x38,0x54,0x20, /* 6 */                         
 
    0x04,0x74,0x0C, /* 7 */                         
 
    0x28,0x54,0x28, /* 8 */                         
 
    0x08,0x54,0x38, /* 9 */                         
 
    0x00,0x50,0x00, /* : */                         
 
    0x80,0x50,0x00, /* ; */                         
 
    0x10,0x28,0x44, /* < */                         
 
    0x28,0x28,0x28, /* = */                  
 
    0x44,0x28,0x10, /* > */                        
 
    0x04,0x54,0x08, /* ? */                         
 
    0x38,0x4C,0x5C, /* @ */                          
 
    0x78,0x14,0x78, /* A */                         
 
    0x7C,0x54,0x28, /* B */                         
 
    0x38,0x44,0x44, /* C */                         
 
    0x7C,0x44,0x38, /* D */                         
 
    0x7C,0x54,0x44, /* E */                         
 
    0x7C,0x14,0x04, /* F */                         
 
    0x38,0x44,0x34, /* G */                         
 
    0x7C,0x10,0x7C, /* H */                         
 
    0x00,0x7C,0x00, /* I */                         
 
    0x20,0x40,0x3C, /* J */                         
 
    0x7C,0x10,0x6C, /* K */                         
 
    0x7C,0x40,0x40, /* L */                         
 
    0x7C,0x08,0x7C, /* M */                         
 
    0x7C,0x04,0x7C, /* N */                         
 
    0x7C,0x44,0x7C, /* O */                         
 
    0x7C,0x14,0x08, /* P */                 
 
    0x38,0x44,0x78, /* Q */                         
 
    0x7C,0x14,0x68, /* R */                         
 
    0x48,0x54,0x24, /* S */                         
 
    0x04,0x7C,0x04, /* T */                         
 
    0x7C,0x40,0x7C, /* U */                         
 
    0x3C,0x40,0x3C, /* V */                         
 
    0x7C,0x20,0x7C, /* W */                         
 
    0x6C,0x10,0x6C, /* X */                         
 
    0x1C,0x60,0x1C, /* Y */                         
 
    0x64,0x54,0x4C, /* Z */                         
 
    0x7C,0x44,0x00, /* [ */                         
 
    0x08,0x10,0x20, /* \ */                         
 
    0x44,0x7C,0x00, /* ] */                         
 
    0x08,0x04,0x08, /* ^ */                         
 
    0x80,0x80,0x80, /* _ */                         
 
    0x04,0x08,0x00  /* ` */                 
 
};
 

	
 
/* System 5x8 */
 
const uint8_t au8FontSystem5x8[]= 
 
{
 
    0x00,0x00,0x00,0x00,0x00, /* Space */
 
    0x00,0x00,0x4f,0x00,0x00, /* ! */
 
    0x00,0x07,0x00,0x07,0x00, /* " */
 
    0x14,0x7f,0x14,0x7f,0x14, /* # */
 
    0x24,0x2a,0x7f,0x2a,0x12, /* 0x */
 
    0x23,0x13,0x08,0x64,0x62, /* % */
 
    0x36,0x49,0x55,0x22,0x20, /* & */
 
    0x00,0x05,0x03,0x00,0x00, /* ' */
 
    0x00,0x1c,0x22,0x41,0x00, /* ( */
 
    0x00,0x41,0x22,0x1c,0x00, /* ) */
 
    0x14,0x08,0x3e,0x08,0x14, /* // */
 
    0x08,0x08,0x3e,0x08,0x08, /* + */
 
    0x50,0x30,0x00,0x00,0x00, /* , */
 
    0x08,0x08,0x08,0x08,0x08, /* - */ 
 
    0x00,0x60,0x60,0x00,0x00, /* . */
 
    0x20,0x10,0x08,0x04,0x02, /* / */
 
    0x3e,0x51,0x49,0x45,0x3e, /* 0 */
 
    0x00,0x42,0x7f,0x40,0x00, /* 1 */
 
    0x42,0x61,0x51,0x49,0x46, /* 2 */
 
    0x21,0x41,0x45,0x4b,0x31, /* 3 */
 
    0x18,0x14,0x12,0x7f,0x10, /* 4 */
 
    0x27,0x45,0x45,0x45,0x39, /* 5 */
 
    0x3c,0x4a,0x49,0x49,0x30, /* 6 */
 
    0x01,0x71,0x09,0x05,0x03, /* 7 */
 
    0x36,0x49,0x49,0x49,0x36, /* 8 */
 
    0x06,0x49,0x49,0x29,0x1e, /* 9 */
 
    0x00,0x36,0x36,0x00,0x00, /* : */
 
    0x00,0x56,0x36,0x00,0x00, /* ; */
 
    0x08,0x14,0x22,0x41,0x00, /* < */
 
    0x14,0x14,0x14,0x14,0x14, /* = */
 
    0x00,0x41,0x22,0x14,0x08, /* > */
 
    0x02,0x01,0x51,0x09,0x06, /* ? */
 
    0x3e,0x41,0x5d,0x55,0x1e, /* @ */
 
    0x7e,0x11,0x11,0x11,0x7e, /* A */
 
    0x7f,0x49,0x49,0x49,0x36, /* B */
 
    0x3e,0x41,0x41,0x41,0x22, /* C */
 
    0x7f,0x41,0x41,0x22,0x1c, /* D */
 
    0x7f,0x49,0x49,0x49,0x41, /* E */
 
    0x7f,0x09,0x09,0x09,0x01, /* F */
 
    0x3e,0x41,0x49,0x49,0x7a, /* G */
 
    0x7f,0x08,0x08,0x08,0x7f, /* H */
 
    0x00,0x41,0x7f,0x41,0x00, /* I */
 
    0x20,0x40,0x41,0x3f,0x01, /* J */
 
    0x7f,0x08,0x14,0x22,0x41, /* K */
 
    0x7f,0x40,0x40,0x40,0x40, /* L */
 
    0x7f,0x02,0x0c,0x02,0x7f, /* M */
 
    0x7f,0x04,0x08,0x10,0x7f, /* N */
 
    0x3e,0x41,0x41,0x41,0x3e, /* O */
 
    0x7f,0x09,0x09,0x09,0x06, /* P */
 
    0x3e,0x41,0x51,0x21,0x5e, /* Q */
 
    0x7f,0x09,0x19,0x29,0x46, /* R */
 
    0x26,0x49,0x49,0x49,0x32, /* S */
 
    0x01,0x01,0x7f,0x01,0x01, /* T */
 
    0x3f,0x40,0x40,0x40,0x3f, /* U */
 
    0x1f,0x20,0x40,0x20,0x1f, /* V */
 
    0x3f,0x40,0x38,0x40,0x3f, /* W */
 
    0x63,0x14,0x08,0x14,0x63, /* X */
 
    0x07,0x08,0x70,0x08,0x07, /* Y */
 
    0x61,0x51,0x49,0x45,0x43, /* Z */
 
    0x00,0x7f,0x41,0x41,0x00, /* [ */
 
    0x02,0x04,0x08,0x10,0x20, /* \ */ 
 
    0x00,0x41,0x41,0x7f,0x00, /* ] */
 
    0x04,0x02,0x01,0x02,0x04, /* ^ */
 
    0x40,0x40,0x40,0x40,0x40, /* _ */
 
    0x00,0x00,0x03,0x05,0x00, /* ` */
 
    0x20,0x54,0x54,0x54,0x78, /* a */
 
    0x7F,0x44,0x44,0x44,0x38, /* b */
 
    0x38,0x44,0x44,0x44,0x44, /* c */
 
    0x38,0x44,0x44,0x44,0x7f, /* d */
 
    0x38,0x54,0x54,0x54,0x18, /* e */
 
    0x04,0x04,0x7e,0x05,0x05, /* f */
 
    0x08,0x54,0x54,0x54,0x3c, /* g */
 
    0x7f,0x08,0x04,0x04,0x78, /* h */
 
    0x00,0x44,0x7d,0x40,0x00, /* i */
 
    0x20,0x40,0x44,0x3d,0x00, /* j */
 
    0x7f,0x10,0x28,0x44,0x00, /* k */
 
    0x00,0x41,0x7f,0x40,0x00, /* l */
 
    0x7c,0x04,0x7c,0x04,0x78, /* m */
 
    0x7c,0x08,0x04,0x04,0x78, /* n */
 
    0x38,0x44,0x44,0x44,0x38, /* o */
 
    0x7c,0x14,0x14,0x14,0x08, /* p */
 
    0x08,0x14,0x14,0x14,0x7c, /* q */
 
    0x7c,0x08,0x04,0x04,0x00, /* r */
 
    0x48,0x54,0x54,0x54,0x24, /* s */
 
    0x04,0x04,0x3f,0x44,0x44, /* t */
 
    0x3c,0x40,0x40,0x20,0x7c, /* u */
 
    0x1c,0x20,0x40,0x20,0x1c, /* v */
 
    0x3c,0x40,0x30,0x40,0x3c, /* w */
 
    0x44,0x28,0x10,0x28,0x44, /* x */
 
    0x0c,0x50,0x50,0x50,0x3c, /* y */
 
    0x44,0x64,0x54,0x4c,0x44, /* z */
 
    0x08,0x36,0x41,0x41,0x00, /* { */
 
    0x00,0x00,0x77,0x00,0x00, /* | */
 
    0x00,0x41,0x41,0x36,0x08, /* } */
 
    0x08,0x08,0x2a,0x1c,0x08, /* <- */
 
    0x08,0x1c,0x2a,0x08,0x08, /* -> */
 
    0xff,0xff,0xff,0xff,0xff, /* */
 
};
 

	
 
/* System 7x8 */
 
const uint8_t au8FontSystem7x8[]= 
 
{
 
     0,   0,   0,   0,   0,   0,   0, //' '
 
     0,   6,  95,  95,   6,   0,   0, //'!'
 
     0,   7,   7,   0,   7,   7,   0, //'"'
 
    20, 127, 127,  20, 127, 127,  20, //'#'
 
    36,  46, 107, 107,  58,  18,   0, //'$'
 
    70, 102,  48,  24,  12, 102,  98, //'%'
 
    48, 122,  79,  93,  55, 122,  72, //'&'
 
     4,   7,   3,   0,   0,   0,   0, //'''
 
     0,  28,  62,  99,  65,   0,   0, //'('
 
     0,  65,  99,  62,  28,   0,   0, //')'
 
     8,  42,  62,  28,  28,  62,  42, //'*'
 
     8,   8,  62,  62,   8,   8,   0, //'+'
 
     0, 128, 224,  96,   0,   0,   0, //','
 
     8,   8,   8,   8,   8,   8,   0, //'-'
 
     0,   0,  96,  96,   0,   0,   0, //'.'
 
    96,  48,  24,  12,   6,   3,   1, //'/'
 
    62, 127, 113,  89,  77, 127,  62, //'0'
 
    64,  66, 127, 127,  64,  64,   0, //'1'
 
    98, 115,  89,  73, 111, 102,   0, //'2'
 
    34,  99,  73,  73, 127,  54,   0, //'3'
 
    24,  28,  22,  83, 127, 127,  80, //'4'
 
    39, 103,  69,  69, 125,  57,   0, //'5'
 
    60, 126,  75,  73, 121,  48,   0, //'6'
 
     3,   3, 113, 121,  15,   7,   0, //'7'
 
    54, 127,  73,  73, 127,  54,   0, //'8'
 
     6,  79,  73, 105,  63,  30,   0, //'9'
 
     0,   0, 102, 102,   0,   0,   0, //':'
 
     0, 128, 230, 102,   0,   0,   0, //';'
 
     8,  28,  54,  99,  65,   0,   0, //'<'
 
    36,  36,  36,  36,  36,  36,   0, //'='
 
     0,  65,  99,  54,  28,   8,   0, //'>'
 
     2,   3,  81,  89,  15,   6,   0, //'?'
 
    62, 127,  65,  93,  93,  31,  30, //'@'
 
    124,126,  19,  19, 126, 124,   0, //'A'
 
    65, 127, 127,  73,  73, 127,  54, //'B'
 
    28,  62,  99,  65,  65,  99,  34, //'C'
 
    65, 127, 127,  65,  99,  62,  28, //'D'
 
    65, 127, 127,  73,  93,  65,  99, //'E'
 
    65, 127, 127,  73,  29,   1,   3, //'F'
 
    28,  62,  99,  65,  81, 115, 114, //'G'
 
    127,127,   8,   8, 127, 127,   0, //'H'
 
     0,  65, 127, 127,  65,   0,   0, //'I'
 
    48, 112,  64,  65, 127,  63,   1, //'J'
 
    65, 127, 127,   8,  28, 119,  99, //'K'
 
    65, 127, 127,  65,  64,  96, 112, //'L'
 
    127,127,  14,  28,  14, 127, 127, //'M'
 
    127,127,   6,  12,  24, 127, 127, //'N'
 
    28,  62,  99,  65,  99,  62,  28, //'O'
 
    65, 127, 127,  73,   9,  15,   6, //'P'
 
    30,  63,  33, 113, 127,  94,   0, //'Q'
 
    65, 127, 127,   9,  25, 127, 102, //'R'
 
    38, 111,  77,  89, 115,  50,   0, //'S'
 
     3,  65, 127, 127,  65,   3,   0, //'T'
 
    127,127,  64,  64, 127, 127,   0, //'U'
 
    31,  63,  96,  96,  63,  31,   0, //'V'
 
    127,127,  48,  24,  48, 127, 127, //'W'
 
    67, 103,  60,  24,  60, 103,  67, //'X'
 
     7,  79, 120, 120,  79,   7,   0, //'Y'
 
    71,  99, 113,  89,  77, 103, 115, //'Z'
 
     0, 127, 127,  65,  65,   0,   0, //'['
 
     1,   3,   6,  12,  24,  48,  96, //'\'
 
     0,  65,  65, 127, 127,   0,   0, //']'
 
     8,  12,   6,   3,   6,  12,   8, //'^'
 
    128,128, 128, 128, 128, 128, 128, //'_'
 
     0,   0,   3,   7,   4,   0,   0, //'`'
 
    32, 116,  84,  84,  60, 120,  64, //'a'
 
    65, 127,  63,  72,  72, 120,  48, //'b'
 
    56, 124,  68,  68, 108,  40,   0, //'c'
 
    48, 120,  72,  73,  63, 127,  64, //'d'
 
    56, 124,  84,  84,  92,  24,   0, //'e'
 
    72, 126, 127,  73,   3,   2,   0, //'f'
 
    56, 188, 164, 164, 252, 120,   0, //'g'
 
    65, 127, 127,   8,   4, 124, 120, //'h'
 
     0,  68, 125, 125,  64,   0,   0, //'i'
 
    96, 224, 128, 128, 253, 125,   0, //'j'
 
    65, 127, 127,  16,  56, 108,  68, //'k'
 
     0,  65, 127, 127,  64,   0,   0, //'l'
 
    120,124,  28,  56,  28, 124, 120, //'m'
 
    124,124,   4,   4, 124, 120,   0, //'n'
 
    56, 124,  68,  68, 124,  56,   0, //'o'
 
    0,  252, 252, 164,  36,  60,  24, //'p'
 
    24,  60,  36, 164, 248, 252, 132, //'q'
 
    68, 124, 120,  76,   4,  28,  24, //'r'
 
    72,  92,  84,  84, 116,  36,   0, //'s'
 
     0,   4,  62, 127,  68,  36,   0, //'t'
 
    60, 124,  64,  64,  60, 124,  64, //'u'
 
    28,  60,  96,  96,  60,  28,   0, //'v'
 
    60, 124, 112,  56, 112, 124,  60, //'w'
 
    68, 108,  56,  16,  56, 108,  68, //'x'
 
    60, 188, 160, 160, 252, 124,   0, //'y'
 
    76, 100, 116,  92,  76, 100,   0, //'z'
 
     8,   8,  62, 119,  65,  65,   0, //'{'
 
     0,   0,   0, 119, 119,   0,   0, //'|'
 
    65,  65, 119,  62,   8,   8,   0, //'}'
 
     2,   3,   1,   3,   2,   3,   1, //'~'
 
    255,129, 129, 129, 129, 129, 255, //'
 
    14, 159, 145, 177, 251,  74,   0 //'Á'
 
};
 
  
 
/* 8x8 Normal */
 
const uint8_t au8Font8x8[]= {
 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,       // ASCII -  32
 
    0x00,0x00,0x00,0x5F,0x5F,0x00,0x00,0x00,       // ASCII -  33
 
    0x00,0x00,0x03,0x07,0x00,0x07,0x03,0x00,       // ASCII -  34
 
    0x00,0x10,0x74,0x1C,0x77,0x1C,0x17,0x04,       // ASCII -  35
 
    0x00,0x24,0x2E,0x2A,0x7F,0x2A,0x3A,0x10,       // ASCII -  36
 
    0x00,0x4C,0x6A,0x76,0x1A,0x6A,0x56,0x33,       // ASCII -  37
 
    0x00,0x30,0x7A,0x4F,0x5D,0x37,0x7A,0x48,       // ASCII -  38
 
    0x00,0x00,0x04,0x07,0x03,0x00,0x00,0x00,       // ASCII -  39
 
    0x00,0x00,0x00,0x1C,0x3E,0x63,0x41,0x00,       // ASCII -  40
 
    0x00,0x00,0x41,0x63,0x3E,0x1C,0x00,0x00,       // ASCII -  41
 
    0x00,0x08,0x2A,0x3E,0x1C,0x3E,0x2A,0x08,       // ASCII -  42
 
    0x00,0x08,0x08,0x3E,0x3E,0x08,0x08,0x00,       // ASCII -  43
 
    0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,       // ASCII -  44
 
    0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00,       // ASCII -  45
 
    0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,       // ASCII -  46
 
    0x00,0x60,0x30,0x18,0x0C,0x06,0x03,0x01,       // ASCII -  47
 
    0x00,0x1C,0x3E,0x61,0x43,0x3E,0x1C,0x00,       // ASCII -  48
 
    0x00,0x00,0x44,0x7F,0x7F,0x40,0x00,0x00,       // ASCII -  49
 
    0x00,0x46,0x67,0x71,0x59,0x4F,0x66,0x00,       // ASCII -  50
 
    0x00,0x22,0x63,0x49,0x4D,0x7F,0x32,0x00,       // ASCII -  51
 
    0x00,0x18,0x1C,0x52,0x7F,0x7F,0x50,0x00,       // ASCII -  52
 
    0x00,0x2F,0x6F,0x45,0x45,0x7D,0x39,0x00,       // ASCII -  53
 
    0x00,0x3C,0x7E,0x4B,0x49,0x79,0x30,0x00,       // ASCII -  54
 
    0x00,0x07,0x43,0x71,0x7D,0x0F,0x03,0x00,       // ASCII -  55
 
    0x00,0x36,0x7F,0x4D,0x59,0x7F,0x36,0x00,       // ASCII -  56
 
    0x00,0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00,       // ASCII -  57
 
    0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00,       // ASCII -  58
 
    0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00,       // ASCII -  59
 
    0x00,0x00,0x08,0x1C,0x36,0x63,0x41,0x00,       // ASCII -  60
 
    0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00,       // ASCII -  61
 
    0x00,0x00,0x41,0x63,0x36,0x1C,0x08,0x00,       // ASCII -  62
 
    0x00,0x02,0x07,0x51,0x59,0x0F,0x06,0x00,       // ASCII -  63
 
    0x00,0x3E,0x41,0x5D,0x55,0x5D,0x51,0x1E,       // ASCII -  64
 
    0x00,0x40,0x70,0x1D,0x17,0x1F,0x78,0x60,       // ASCII -  65
 
    0x00,0x41,0x7F,0x7F,0x49,0x4F,0x7E,0x30,       // ASCII -  66
 
    0x00,0x1C,0x3E,0x63,0x41,0x41,0x42,0x27,       // ASCII -  67
 
    0x00,0x41,0x7F,0x7F,0x41,0x63,0x3E,0x1C,       // ASCII -  68
 
    0x00,0x41,0x7F,0x7F,0x49,0x5D,0x41,0x63,       // ASCII -  69
 
    0x00,0x41,0x7F,0x7F,0x49,0x1D,0x01,0x03,       // ASCII -  70
 
    0x00,0x1C,0x3E,0x63,0x41,0x51,0x72,0x77,       // ASCII -  71
 
    0x00,0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00,       // ASCII -  72
 
    0x00,0x00,0x41,0x7F,0x7F,0x41,0x00,0x00,       // ASCII -  73
 
    0x00,0x30,0x70,0x41,0x41,0x7F,0x3F,0x01,       // ASCII -  74
 
    0x00,0x7F,0x7F,0x08,0x1C,0x77,0x63,0x41,       // ASCII -  75
 
    0x00,0x41,0x7F,0x7F,0x41,0x40,0x60,0x70,       // ASCII -  76
 
    0x00,0x7F,0x7E,0x0C,0x18,0x0C,0x7E,0x7F,       // ASCII -  77
 
    0x00,0x7F,0x7E,0x0C,0x18,0x30,0x7F,0x7F,       // ASCII -  78
 
    0x00,0x1C,0x3E,0x63,0x41,0x63,0x3E,0x1C,       // ASCII -  79
 
    0x00,0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06,       // ASCII -  80
 
    0x00,0x1C,0x3E,0x63,0x51,0x63,0x3E,0x1C,       // ASCII -  81
 
    0x00,0x7F,0x7F,0x09,0x19,0x7F,0x66,0x40,       // ASCII -  82
 
    0x00,0x66,0x6F,0x4D,0x59,0x7B,0x33,0x00,       // ASCII -  83
 
    0x00,0x03,0x41,0x7F,0x7F,0x41,0x03,0x00,       // ASCII -  84
 
    0x00,0x3F,0x7F,0x40,0x40,0x40,0x7F,0x3F,       // ASCII -  85
 
    0x00,0x03,0x0F,0x3D,0x70,0x1D,0x07,0x01,       // ASCII -  86
 
    0x00,0x0F,0x7F,0x30,0x1C,0x30,0x7F,0x0F,       // ASCII -  87
 
    0x00,0x63,0x77,0x1C,0x1C,0x77,0x63,0x00,       // ASCII -  88
 
    0x01,0x03,0x47,0x7C,0x78,0x47,0x03,0x01,       // ASCII -  89
 
    0x00,0x67,0x73,0x59,0x4D,0x67,0x73,0x00,       // ASCII -  90
 
    0x00,0x00,0x00,0x7F,0x7F,0x41,0x41,0x00,       // ASCII -  91
 
    0x00,0x01,0x03,0x06,0x0C,0x18,0x30,0x60,       // ASCII -  92
 
    0x00,0x00,0x41,0x41,0x7F,0x7F,0x00,0x00,       // ASCII -  93
 
    0x00,0x00,0x04,0x06,0x03,0x06,0x04,0x00,       // ASCII -  94
 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,       // ASCII -  95
 
    0x00,0x00,0x01,0x03,0x06,0x04,0x00,0x00,       // ASCII -  96
 
    0x00,0x68,0x6C,0x54,0x54,0x3C,0x78,0x40,       // ASCII -  97
 
    0x00,0x41,0x7F,0x3F,0x6C,0x44,0x7C,0x38,       // ASCII -  98
 
    0x00,0x38,0x7C,0x44,0x44,0x6C,0x2C,0x00,       // ASCII -  99
 
    0x00,0x38,0x7C,0x44,0x49,0x3F,0x7F,0x40,       // ASCII - 100
 
    0x00,0x38,0x7C,0x54,0x54,0x5C,0x58,0x00,       // ASCII - 101
 
    0x00,0x00,0x48,0x7E,0x7F,0x49,0x0B,0x02,       // ASCII - 102
 
    0x00,0x48,0x7C,0x34,0x34,0x2C,0x68,0x44,       // ASCII - 103
 
    0x00,0x41,0x7F,0x7F,0x08,0x04,0x7C,0x78,       // ASCII - 104
 
    0x00,0x00,0x44,0x7D,0x7D,0x40,0x00,0x00,       // ASCII - 105
 
    0x00,0x60,0x60,0x04,0x7D,0x7D,0x00,0x00,       // ASCII - 106
 
    0x00,0x41,0x7F,0x7F,0x10,0x78,0x6C,0x44,       // ASCII - 107
 
    0x00,0x00,0x41,0x7F,0x7F,0x40,0x00,0x00,       // ASCII - 108
 
    0x00,0x7C,0x7C,0x0C,0x78,0x0C,0x7C,0x78,       // ASCII - 109
 
    0x00,0x44,0x7C,0x7C,0x08,0x04,0x7C,0x78,       // ASCII - 110
 
    0x00,0x38,0x7C,0x44,0x44,0x7C,0x38,0x00,       // ASCII - 111
 
    0x00,0x04,0x7C,0x78,0x24,0x24,0x3C,0x18,       // ASCII - 112
 
    0x00,0x18,0x3C,0x24,0x24,0x78,0x7C,0x00,       // ASCII - 113
 
    0x00,0x44,0x7C,0x78,0x4C,0x04,0x1C,0x18,       // ASCII - 114
 
    0x00,0x48,0x5C,0x5C,0x74,0x74,0x24,0x00,       // ASCII - 115
 
    0x00,0x00,0x04,0x3E,0x7F,0x44,0x24,0x00,       // ASCII - 116
 
    0x00,0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40,       // ASCII - 117
 
    0x00,0x04,0x1C,0x3C,0x60,0x30,0x1C,0x04,       // ASCII - 118
 
    0x00,0x1C,0x7C,0x30,0x1C,0x30,0x7C,0x1C,       // ASCII - 119
 
    0x00,0x44,0x6C,0x3C,0x10,0x78,0x6C,0x44,       // ASCII - 120
 
    0x00,0x44,0x4C,0x1C,0x70,0x64,0x1C,0x0C,       // ASCII - 121
 
    0x00,0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00,       // ASCII - 122
 
    0x00,0x08,0x08,0x3E,0x77,0x41,0x41,0x00,       // ASCII - 123
 
    0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,       // ASCII - 124
 
    0x00,0x41,0x41,0x77,0x3E,0x08,0x08,0x00,       // ASCII - 125
 
    0x00,0x02,0x01,0x01,0x03,0x02,0x02,0x01,       // ASCII - 126
 
    0x00,0x60,0x78,0x4E,0x47,0x5E,0x78,0x60,       // ASCII - 127
 
    0x00,0x1C,0x3E,0x23,0x41,0x41,0x42,0x27,       // ASCII - 128
 
    0x00,0x3D,0x7D,0x40,0x41,0x3D,0x7C,0x40,       // ASCII - 129
 
};
 

	
 
/* 8x8 Thin */
 
const uint8_t au8Font8x8Thin[]= {
 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 
    0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,
 
    0x00,0x00,0x07,0x00,0x00,0x07,0x00,0x00,
 
    0x00,0x14,0x7F,0x14,0x14,0x7F,0x14,0x00,
 
    0x00,0x24,0x2A,0x6B,0x6B,0x2A,0x12,0x00,
 
    0x00,0x46,0x26,0x10,0x08,0x64,0x62,0x00,
 
    0x30,0x4A,0x45,0x4D,0x32,0x48,0x48,0x00,
 
    0x00,0x00,0x04,0x03,0x00,0x00,0x00,0x00,
 
    0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00,
 
    0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00,
 
    0x08,0x2A,0x1C,0x1C,0x1C,0x2A,0x08,0x00,
 
    0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00,
 
    0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,
 
    0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
 
    0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,
 
    0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x00,
 
    0x00,0x3E,0x61,0x51,0x49,0x45,0x3E,0x00,
 
    0x00,0x44,0x42,0x7F,0x40,0x40,0x00,0x00,
 
    0x00,0x62,0x51,0x51,0x49,0x49,0x66,0x00,
 
    0x00,0x22,0x41,0x49,0x49,0x49,0x36,0x00,
 
    0x10,0x18,0x14,0x52,0x7F,0x50,0x10,0x00,
 
    0x00,0x27,0x45,0x45,0x45,0x45,0x39,0x00,
 
    0x00,0x3C,0x4A,0x49,0x49,0x49,0x30,0x00,
 
    0x00,0x03,0x01,0x71,0x09,0x05,0x03,0x00,
 
    0x00,0x36,0x49,0x49,0x49,0x49,0x36,0x00,
 
    0x00,0x06,0x49,0x49,0x49,0x29,0x1E,0x00,
 
    0x00,0x00,0x00,0x66,0x00,0x00,0x00,0x00,
 
    0x00,0x00,0x80,0x66,0x00,0x00,0x00,0x00,
 
    0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00,
 
    0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x00,
 
    0x00,0x00,0x00,0x41,0x22,0x14,0x08,0x00,
 
    0x00,0x02,0x01,0x01,0x51,0x09,0x06,0x00,
 
    0x00,0x3E,0x41,0x5D,0x55,0x55,0x1E,0x00,
 
    0x00,0x7C,0x12,0x11,0x11,0x12,0x7C,0x00,
 
    0x00,0x41,0x7F,0x49,0x49,0x49,0x36,0x00,
 
    0x00,0x1C,0x22,0x41,0x41,0x41,0x22,0x00,
 
    0x00,0x41,0x7F,0x41,0x41,0x22,0x1C,0x00,
 
    0x00,0x41,0x7F,0x49,0x5D,0x41,0x63,0x00,
 
    0x00,0x41,0x7F,0x49,0x1D,0x01,0x03,0x00,
 
    0x00,0x1C,0x22,0x41,0x51,0x51,0x72,0x00,
 
    0x00,0x7F,0x08,0x08,0x08,0x08,0x7F,0x00,
 
    0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00,
 
    0x00,0x30,0x40,0x40,0x41,0x3F,0x01,0x00,
 
    0x00,0x41,0x7F,0x08,0x14,0x22,0x41,0x40,
 
    0x00,0x41,0x7F,0x41,0x40,0x40,0x60,0x00,
 
    0x00,0x7F,0x01,0x02,0x04,0x02,0x01,0x7F,
 
    0x00,0x7F,0x01,0x02,0x04,0x08,0x7F,0x00,
 
    0x00,0x3E,0x41,0x41,0x41,0x41,0x3E,0x00,
 
    0x00,0x41,0x7F,0x49,0x09,0x09,0x06,0x00,
 
    0x00,0x1E,0x21,0x21,0x31,0x21,0x5E,0x40,
 
    0x00,0x41,0x7F,0x49,0x19,0x29,0x46,0x00,
 
    0x00,0x26,0x49,0x49,0x49,0x49,0x32,0x00,
 
    0x00,0x03,0x01,0x41,0x7F,0x41,0x01,0x03,
 
    0x00,0x3F,0x40,0x40,0x40,0x40,0x3F,0x00,
 
    0x00,0x0F,0x10,0x20,0x40,0x20,0x10,0x0F,
 
    0x00,0x3F,0x40,0x40,0x38,0x40,0x40,0x3F,
 
    0x00,0x41,0x22,0x14,0x08,0x14,0x22,0x41,
 
    0x00,0x01,0x02,0x44,0x78,0x44,0x02,0x01,
 
    0x00,0x43,0x61,0x51,0x49,0x45,0x43,0x61,
 
    0x00,0x7F,0x41,0x41,0x41,0x00,0x00,0x00,
 
    0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x00,
 
    0x00,0x41,0x41,0x41,0x7F,0x00,0x00,0x00,
 
    0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x00,
 
    0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
 
    0x00,0x00,0x00,0x03,0x04,0x00,0x00,0x00,
 
    0x00,0x20,0x54,0x54,0x54,0x54,0x78,0x40,
 
    0x00,0x01,0x7F,0x30,0x48,0x48,0x48,0x30,
 
    0x00,0x38,0x44,0x44,0x44,0x44,0x28,0x00,
 
    0x00,0x30,0x48,0x48,0x48,0x31,0x7F,0x40,
 
    0x00,0x38,0x54,0x54,0x54,0x54,0x18,0x00,
 
    0x00,0x00,0x48,0x7E,0x49,0x01,0x02,0x00,
 
    0x00,0x98,0xA4,0xA4,0xA4,0xA4,0x78,0x04,
 
    0x00,0x41,0x7F,0x08,0x04,0x04,0x78,0x00,
 
    0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00,
 
    0x00,0x60,0x80,0x80,0x80,0x84,0x7D,0x00,
 
    0x00,0x01,0x7F,0x10,0x28,0x44,0x40,0x00,
 
    0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00,
 
    0x00,0x7C,0x04,0x04,0x78,0x04,0x04,0x78,
 
    0x00,0x7C,0x08,0x04,0x04,0x04,0x78,0x00,
 
    0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00,
 
    0x00,0x84,0xFC,0x98,0x24,0x24,0x18,0x00,
 
    0x00,0x18,0x24,0x24,0x98,0xFC,0x84,0x00,
 
    0x00,0x44,0x7C,0x48,0x04,0x04,0x18,0x00,
 
    0x00,0x48,0x54,0x54,0x54,0x54,0x24,0x00,
 
    0x00,0x04,0x04,0x3F,0x44,0x44,0x20,0x00,
 
    0x00,0x3C,0x40,0x40,0x40,0x20,0x7C,0x00,
 
    0x00,0x0C,0x10,0x20,0x40,0x20,0x10,0x0C,
 
    0x00,0x3C,0x40,0x40,0x38,0x40,0x40,0x3C,
 
    0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,
 
    0x00,0x9C,0xA0,0xA0,0xA0,0xA0,0x7C,0x00,
 
    0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00,
 
    0x00,0x08,0x08,0x36,0x41,0x41,0x00,0x00,
 
    0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00,
 
    0x00,0x00,0x41,0x41,0x36,0x08,0x08,0x00,
 
    0x00,0x02,0x01,0x01,0x02,0x02,0x01,0x00,
 
    0x00,0x70,0x48,0x44,0x42,0x44,0x48,0x70,
 
    0x00,0x0E,0x91,0x91,0xB1,0xB1,0x4A,0x00,
 
    0x00,0x3A,0x40,0x40,0x40,0x7A,0x40,0x00,
 
    0x00,0x38,0x54,0x54,0x55,0x55,0x18,0x00,
 
    0x00,0x22,0x55,0x55,0x55,0x79,0x42,0x00,
 
    0x00,0x21,0x54,0x54,0x54,0x78,0x41,0x00,
 
    0x00,0x20,0x55,0x55,0x54,0x78,0x40,0x00,
 
    0x00,0x20,0x54,0x55,0x54,0x78,0x40,0x00,
 
    0x00,0x18,0x24,0xA4,0xA4,0xE4,0x40,0x00,
 
    0x00,0x3A,0x55,0x55,0x55,0x55,0x1A,0x00,
 
    0x00,0x39,0x54,0x54,0x54,0x54,0x19,0x00,
 
    0x00,0x38,0x55,0x55,0x54,0x54,0x18,0x00,
 
    0x00,0x00,0x01,0x44,0x7C,0x41,0x00,0x00,
 
    0x02,0x01,0x45,0x7D,0x41,0x01,0x02,0x00,
 
    0x00,0x00,0x01,0x45,0x7C,0x40,0x00,0x00,
 
    0x00,0x79,0x14,0x12,0x12,0x14,0x79,0x00,
 
    0x00,0x70,0x28,0x2B,0x2B,0x28,0x70,0x00,
 
    0x00,0x44,0x7C,0x54,0x55,0x45,0x00,0x00,
 
    0x00,0x20,0x54,0x54,0x58,0x38,0x54,0x54,
 
    0x00,0x7C,0x0A,0x09,0x09,0x7F,0x49,0x49,
 
    0x00,0x30,0x4A,0x49,0x49,0x4A,0x30,0x00,
 
    0x00,0x32,0x48,0x48,0x48,0x48,0x32,0x00,
 
    0x00,0x30,0x49,0x4A,0x48,0x48,0x30,0x00,
 
    0x00,0x38,0x42,0x41,0x41,0x42,0x38,0x00,
 
    0x00,0x38,0x41,0x42,0x40,0x40,0x38,0x00,
 
    0x00,0x1A,0xA0,0xA0,0xA0,0xA0,0x7A,0x00,
 
    0x00,0x19,0x24,0x42,0x42,0x24,0x19,0x00,
 
    0x00,0x3D,0x40,0x40,0x40,0x40,0x3D,0x00,
 
    0x00,0x18,0x24,0x24,0xE7,0x24,0x24,0x00,
 
    0x00,0x68,0x5E,0x49,0x41,0x42,0x20,0x00,
 
    0x00,0x15,0x16,0x7C,0x16,0x15,0x00,0x00,
 
    0x81,0xFF,0x85,0x05,0x17,0xFA,0x90,0x50,
 
    0x40,0x88,0x88,0x7F,0x09,0x09,0x02,0x00,
 
    0x00,0x20,0x54,0x54,0x55,0x79,0x40,0x00,
 
};
 

	
ssd1306.c
Show inline comments
 
/*******************************************************************************
 
* File Name          : ssd1306.c
 
* Author             : lxyppc
 
* Version            : V1.0
 
* Date               : 10-01-21
 
* Description        : ssd1306 operations
 
*                      the SSH1101A is compatible with ssd1306
 
*******************************************************************************/
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32l100c_discovery.h"
 
#include "bsp.h"
 
#include "ssd1306.h"
 
#include "DrawText.h"
 
 
/* Private typedef -----------------------------------------------------------*/
 
/* Private define ------------------------------------------------------------*/
 
#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
 
#define   SSD1306_Y_PIXEL   32
 
 
/* Private macro -------------------------------------------------------------*/
 
#define   ssd1306_Buffer    (_SSD1306_Buffer + SSD1306_COLUMN_MARGIN_START)
 
 
/* Private variables ---------------------------------------------------------*/
 
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;
 
static  uint8_t  curContrast = 0xCC;
 
static  uint8_t  lastContrast = 0xCC;
 
 
/* Private function prototypes -----------------------------------------------*/
 
void  WriteCommand(unsigned char command);
 
void  WriteData(unsigned char data);
 
void  OnPageTransferDone(void);
 
unsigned long ssd1306_OFF(void);
 
unsigned long ssd1306_ON(void);
 
unsigned char* ssd1306_GetBuffer()
 
{
 
  return ssd1306_Buffer;
 
}
 
/*******************************************************************************
 
* Function Name  : WriteCommand
 
* Description    : Write command to the ssd1306
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void WriteCommand(unsigned char command)
 
{
 
  SSD_A0_Low();
 
  SPI_SendByte(command);
 
  SPI_Wait();
 
}
 
 
/*******************************************************************************
 
* Function Name  : WriteData
 
* Description    : Write data to the ssd1306
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void WriteData(unsigned char data)
 
{
 
  SSD_A0_High();
 
  SPI_SendByte(data);
 
  SPI_Wait();
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_Init
 
* Description    : Initialize the ssd1306
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void ssd1306_Init(void)
 
{
 
 
  /* Generate a reset */
 
  SSD_Reset_Low();
 
  uint32_t i;
 
  for(i=5000; i>1; i--) 
 
  SSD_Reset_High();
 
 
 
  WriteCommand(0xAE);
 
  WriteCommand(0xD5);
 
  WriteCommand(0x80);
 
  WriteCommand(0xA8);
 
  WriteCommand(0x1F);
 
  WriteCommand(0xD3);
 
  WriteCommand(0x00);
 
  WriteCommand(0x40 | 0x00); // line #0
 
  WriteCommand(0x8D);
 
  WriteCommand(0x14); //10 or 14 if not externalvcc
 
  WriteCommand(0x20);
 
  WriteCommand(0x00);
 
  WriteCommand(0xA0 | 0x1); // segremap
 
  WriteCommand(0xC8); // comscandep
 
  WriteCommand(0xDA); // setcompins 
 
  WriteCommand(0x02);
 
  WriteCommand(0x81); // contrast
 
  WriteCommand(0x0F); // contrast value. 8f is a good one.
 
  WriteCommand(0xD9);
 
  WriteCommand(0xF1); //22 or F1 if not externalvcc
 
  WriteCommand(0xDB);
 
  WriteCommand(0x40);
 
  WriteCommand(0xA4); // dispalyallon_resume
 
  WriteCommand(0xA6); // normaldisplay
 
 
  WriteCommand(0xAF); // display on 
 
 
 
  // Clear buffer
 
//  for(i=0;i<900;i++)
 
//    ssd1306_Buffer[i] = 0;
 
  
 
  /*************************************************
 
  // ssd1306 Initialization Command
 
  *************************************************/
 
 /* 
 
  // Lower Column Address
 
  WriteCommand(0x00); /* Set Lower Column Address */
 
  WriteCommand(0x00); // Set Lower Column Address 
 
  GPIO_SetBits(GPIOA,GPIO_Pin_15);//turn on status LED
 
  // High Column Address
 
  WriteCommand(0x10); /* Set Higher Column Address*/
 
  WriteCommand(0x10); // Set Higher Column Address
 
  // Display Start Line
 
  WriteCommand(0x40); /* Set Display Start Line */
 
  WriteCommand(0x40); // Set Display Start Line 
 
#ifdef    DEBUG_BOARD
 
  curContrast = lastContrast = 0x30;
 
#else
 
  curContrast = lastContrast = 0xCF;
 
#endif
 
  // Contrast Control Register
 
  WriteCommand(0x81); /* Set Contrast Control */
 
  WriteCommand(lastContrast); /* 0 ~ 255 0x1f*/
 
  WriteCommand(0x81); // Set Contrast Control 
 
  WriteCommand(lastContrast); // 0 ~ 255 0x1f
 
  
 
  // Re-map
 
  WriteCommand(0xA1); /* [A0]:column address 0 is map 
 
  to SEG0 , [A1]: columnaddress 131 is map to SEG0*/ 
 
  WriteCommand(0xA1); // [A0]:column address 0 is map to SEG0 , [A1]: columnaddress 131 is map to SEG0 
 
  // Entire Display ON/OFF
 
  WriteCommand(0xA4); /* A4=ON */
 
  WriteCommand(0xA4); // A4=ON 
 
  // Normal or Inverse Display
 
  WriteCommand(0XA6); /* Normal Display*/
 
  WriteCommand(0XA6); // Normal Display
 
  // Multiplex Ratio
 
  WriteCommand(0xA8); /* Set Multiplex Ratio */
 
  WriteCommand(0x3f); /* Set to 36 Mux*/
 
  WriteCommand(0xA8); // Set Multiplex Ratio 
 
  WriteCommand(0x3f); // Set to 36 Mux
 
  // Set DC-DC
 
  WriteCommand(0xAD); /* Set DC-DC */
 
  WriteCommand(0x8B); /* 8B=ON, 8A=Off */
 
  WriteCommand(0xAD); // Set DC-DC 
 
  WriteCommand(0x8B); // 8B=ON, 8A=Off 
 
 
 
 
 
  // Display ON/OFF
 
  WriteCommand(0xAE); /* AF=ON , AE=OFF*/
 
  WriteCommand(0xAE); // AF=ON , AE=OFF
 
  // Display Offset
 
  WriteCommand(0xD3); /* Set Display Offset */
 
  WriteCommand(0x00); /* No offset */
 
  WriteCommand(0xD3); // Set Display Offset 
 
  WriteCommand(0x00); // No offset 
 
  // Display Clock Divide
 
  WriteCommand(0xD5); /* Set Clock Divide */
 
  WriteCommand(0x20); /* Set to 80Hz */
 
  WriteCommand(0xD5); // Set Clock Divide 
 
  WriteCommand(0x20); // Set to 80Hz 
 
  // Area Color Mode
 
  WriteCommand(0xD8); /* Set Area Color On or Off*/
 
  WriteCommand(0x00); /* Mono Mode */
 
  WriteCommand(0xD8); // Set Area Color On or Off
 
  WriteCommand(0x00); // Mono Mode 
 
  // COM Pins Hardware Configuration
 
  WriteCommand(0xDA); /* Set Pins HardwareConfiguration */
 
  WriteCommand(0xDA); // Set Pins HardwareConfiguration 
 
  WriteCommand(0x12);
 
  // VCOMH
 
  WriteCommand(0xDB); /* Set VCOMH */
 
  WriteCommand(0xDB); // Set VCOMH 
 
  WriteCommand(0x00);
 
  // VP
 
  WriteCommand(0xD9); /* Set VP */
 
  WriteCommand(0x22); /* P1=2 , P2=2 */
 
  WriteCommand(0xD9); // Set VP 
 
  WriteCommand(0x22); // P1=2 , P2=2 
 
  
 
  // Set Common output scan direction
 
  WriteCommand(0xc8);/* Set COM scan direction */
 
  WriteCommand(0xc8);// Set COM scan direction 
 
  
 
  // For SSD1306 Set the address mode
 
  WriteCommand(0x20);/* Set address mode */
 
  WriteCommand(0x00);/* Set address mode horizontal */
 
  WriteCommand(0x20);// Set address mode 
 
  WriteCommand(0x00);// Set address mode horizontal 
 
  
 
  // Set the page start address
 
  WriteCommand(0xb0);
 
  WriteCommand(0x00);
 
  WriteCommand(0x10);
 
  
 
  /* Turn on the controller */
 
  // Turn on the controller 
 
  pre_on = ssd1306_ON();
 
//  // Set Charge pump
 
//  WriteCommand(0x8D); /* Set Charge pump */
 
//  WriteCommand(0x14); /* 0x14=ON, 0x10=Off */
 
//  WriteCommand(0x8D); // Set Charge pump 
 
//  WriteCommand(0x14); // 0x14=ON, 0x10=Off 
 
//  
 
//  // Turn on the display
 
//  WriteCommand(0xaf);
 
*/
 
}
 
 
void ssd1306_block_write(void)
 
{
 
 
 
  // Set col start addr to 0
 
  WriteCommand(0x21); 
 
  WriteCommand(0x00); 
 
  // Set col end addr to width - 1
 
  WriteCommand(127);
 
 
  // Set page addr
 
  WriteCommand(0x22);
 
  WriteCommand(0x00); // start page addr
 
  WriteCommand(4); // end page addr (height / 8)
 
 
 
  uint32_t i = 0;
 
  for(i=0;i<1024;i++)
 
 
 
 
  for(i=0;i<512;i++)
 
    WriteData(ssd1306_Buffer[i]);
 
//  for(i=0;i<512;i++)
 
             // * * * * 
 
//    WriteData(0b00000011);
 
}
 
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_TurnOff
 
* Description    : Turn off the ssd1306 controller
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_TurnOff(void)
 
{
 
  pre_on = 0;
 
  return iS_SSD_On;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_TurnOn
 
* Description    : Turn off the ssd1306 controller
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_TurnOn(void)
 
{
 
  pre_on = 1;
 
  return iS_SSD_On;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_SetContrast
 
* Description    : Set the ssd1306 contrast
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned char ssd1306_SetContrast(unsigned char contrast)
 
{
 
  curContrast = contrast;
 
  return lastContrast;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_GetContrast
 
* Description    : Get the ssd1306 contrast
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned char ssd1306_GetContrast()
 
{
 
  return lastContrast;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_OFF
 
* Description    : Turn off the ssd1306 controller
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_OFF(void)
 
{
 
  if(iS_SSD_On){
 
#ifdef  DEBUG_UI
 
    uint32_t i = 0;
 
    for(i=0;i<ssd1306_COLUMN_NUMBER*SSD1306_PAGE_NUMBER;i++){
 
      ssd1306_Buffer[i] = 0;
 
    }
 
#else
 
    // Turn off the display
 
    WriteCommand(0xae);
 
    
 
    // Set Charge pump
 
    WriteCommand(0x8D); /* Set Charge pump */
 
    WriteCommand(0x10); /* 0x14=ON, 0x10=Off */
 
#endif
 
    iS_SSD_On = 0;
 
  }
 
  return iS_SSD_On;
 
}
 
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_ON
 
* Description    : Turn on the ssd1306 controller
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_ON(void)
 
{
 
  if(!iS_SSD_On){
 
#ifdef  DEBUG_UI
 
#else
 
  #ifdef    DEBUG_BOARD
 
  #else
 
    // Set Charge pump
 
    WriteCommand(0x8D); /* Set Charge pump */
 
    WriteCommand(0x14); /* 0x14=ON, 0x10=Off */
 
  #endif
 
    // Turn on the display
 
    WriteCommand(0xaf);
 
#endif
 
    iS_SSD_On = 1;
 
  }
 
  return iS_SSD_On;
 
}
 
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_IsOn
 
* Description    : Check whether the ssd1306 is on or off
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_IsOn(void)
 
{
 
  return iS_SSD_On;
 
}
 
 
/*******************************************************************************
 
* Function Name  : OnPageTransferDone
 
* Description    : Called when each page transfer done
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void  OnPageTransferDone(void)
 
{
 
  if(pageIndex == SSD1306_PAGE_NUMBER){
 
    pageIndex = 0;
 
    return;
 
  }
 
#ifdef    DEBUG_BOARD
 
  WriteCommand(0xb0 + pageIndex);
 
  if(pageIndex == 0){
 
    WriteCommand(0x00);
 
    WriteCommand(0x10);
 
  }
 
  SSD_A0_High();
 
  DMA1_Channel5->CCR &= ((uint32_t)0xFFFFFFFE);
 
  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_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 = SSD1306_PAGE_NUMBER;
 
#endif
 
}
 
 
/*******************************************************************************
 
* Function Name  : DMA1_Channel5_IRQHandler
 
* Description    : This function handles DMA1 Channel 5 interrupt request.
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void DMA_Handler_SSD_1306(void) //DMA1_Channel5_IRQHandler(void)
 
{
 
  if(DMA_GetITStatus(DMA1_IT_TC5)){
 
    DMA_ClearITPendingBit(DMA1_IT_GL5);
 
    OnPageTransferDone();
 
  }
 
}
 
 
/*******************************************************************************
 
* Function Name  : StartPageTransfer
 
* Description    : Start a new page transfer
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void StartPageTransfer(void)
 
{
 
  pageIndex = 0;
 
  if(pre_on){
 
    if(iS_SSD_On == 0){
 
      pre_on = ssd1306_ON();
 
    }
 
  }else{
 
    if(iS_SSD_On){
 
      pre_on = ssd1306_OFF();
 
    }
 
  }
 
  if( curContrast != lastContrast ){
 
    lastContrast = curContrast;
 
    WriteCommand(0x81); /* Set Contrast Control */
 
    WriteCommand(lastContrast); /* 0 ~ 255 0x1f*/
 
  }
 
  
 
  if(iS_SSD_On){
 
    OnPageTransferDone();
 
  }
 
}
 
 
/*******************************************************************************
 
  Display related functions
 
 ******************************************************************************/
 
/*******************************************************************************
 
* Function Name  : ssd1306_DrawBlock
 
* Description    : Draw a block with specify data to ssd1306
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_DrawBlock(
 
  Pos_t x,
 
  Pos_t y,
 
  Pos_t cx,
 
  Pos_t cy,
 
  const unsigned char* data)
 
{
 
  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){
 
    unsigned char mask1 = (1<<offset1)-1;
 
    unsigned char mask2 = ~((1<<offset2)-1);
 
    cy = (cy+offset1)/8;
 
   
 
    Pos_t i = 0;
 
    for(i=0;i<cx;i++){
 
      Pos_t j = 0;
 
      unsigned short tmp = *pStart & mask1;
 
      for(;j<cy;j++){
 
        tmp |= (((unsigned short)data[j*cx])<<offset1);
 
        *(pStart + j*SSD1306_COLUMN_NUMBER) = tmp;
 
        tmp>>=8;
 
      }
 
      if(offset2){
 
        tmp |= ((((unsigned short)data[j*cx])<<offset1) & (~mask2))
 
            | *(pStart + j*SSD1306_COLUMN_NUMBER) & mask2;
 
        *(pStart + j*SSD1306_COLUMN_NUMBER) = tmp;
 
      }
 
      data++;
 
      pStart++;
 
    }
 
  }else{
 
    unsigned char mask1 = ~((1<<offset1)-1);
 
    unsigned char mask2 = ((1<<offset2)-1);
 
    cy = (cy+offset1)/8;
 
 
    Pos_t i = 0;
 
    for(i=0;i<cx;i++){
 
      Pos_t j = 1;
 
      *pStart ^= mask1;
 
      for(;j<cy;j++){
 
        *(pStart + j*SSD1306_COLUMN_NUMBER) ^= 0xFF;
 
      }
 
      if(offset2){
 
        *(pStart + j*SSD1306_COLUMN_NUMBER) ^= mask2;
 
      }
 
      pStart++;
 
    }
 
  }
 
  
 
  
 
//  if(!offset){
 
//    for(Pos_t i=0;i<cx;i++){
 
//      unsigned char tmp;
 
//      Pos_t j = 0;
 
//      for(;j<cy/8;j++){
 
//        tmp = data[i+j*cx];
 
//        *(pStart + j*ssd1306_COLUMN_NUMBER + i + x) = tmp;
 
//      }
 
//      if(cy&0x7){
 
//        unsigned char mask1 = (1<<(cy&7)) - 1;
 
//        unsigned char mask2 = 0xFF - mask1;
 
//        tmp = (data[i+j*cx] & mask1)
 
//            | (*(pStart + j*ssd1306_COLUMN_NUMBER + i + x) & mask2);
 
//        *(pStart + j*ssd1306_COLUMN_NUMBER + i + x) = tmp;
 
//      }
 
//    }
 
//  }else{
 
//    for(Pos_t i=0;i<cx;i++){
 
//      unsigned short tmp;
 
//      for(Pos_t j=0;j<cy/8;j++){
 
//        if(j == 0){
 
//          // First line
 
//          tmp = *(pStart + j*ssd1306_COLUMN_NUMBER + i + x) & mask;
 
//        }
 
//        tmp |= (((unsigned short)data[i+j*cx])<<offset);
 
//        *(pStart + j*ssd1306_COLUMN_NUMBER + i + x) = tmp;
 
//        tmp>>=8;
 
//        if(j == (cy/8)-1){
 
//          // Last line
 
//          *(pStart + (j+1)*ssd1306_COLUMN_NUMBER + i + x) &= ~mask;
 
//          *(pStart + (j+1)*ssd1306_COLUMN_NUMBER + i + x) |= tmp;
 
//        }
 
//      }
 
//    }
 
//  }
 
  
 
  return 0;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_DrawPoint
 
* Description    : Draw a point with specify data to ssd1306
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_DrawPoint(
 
  Pos_t x,
 
  Pos_t y,
 
  Color_t color)
 
{
 
  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;
 
  }else{
 
    *pStart &= ~mask;
 
  }
 
  return 0;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_ReadPoint
 
* Description    : Read a point from ssd1306
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
unsigned long ssd1306_ReadPoint(
 
  Pos_t x,
 
  Pos_t y)
 
{
 
  unsigned char* pStart = ssd1306_Buffer + (y/8)*SSD1306_COLUMN_NUMBER + x;
 
  unsigned char mask = 1<<(y%8);
 
  return *pStart&mask ? 1 : 0;
 
}
 
 
/*******************************************************************************
 
* Function Name  : ssd1306_ClearScreen
 
* Description    : Clear the screen contents
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void  ssd1306_FillScreen(Color_t color)
 
{
 
  unsigned char mask = color ? 0xFF : 0;
 
  unsigned long i = 0;
 
  for(i=0;i<SSD1306_COLUMN_NUMBER*SSD1306_PAGE_NUMBER;i++){
 
    ssd1306_Buffer[i] = mask;
 
  }
 
}
 
 
const DeviceProp  ssd1306_Prop =
 
{
 
  .pfnDrawBlok = ssd1306_DrawBlock,
 
  .pfnDrawPoint = ssd1306_DrawPoint,
 
  .xPixel = 128,
 
  .yPixel = 64,
 
};
 
 
 
 
 
 
 
 
 
 
/*
 
void ssd1306_DrawChar(uint8_t x, uint8_t y, uint8_t c, struct FONT_DEF font)
 
{
 
  uint8_t col, column[font.u8Width];
 
 
  // Check if the requested character is available
 
  if ((c >= font.u8FirstChar) && (c <= font.u8LastChar))
 
  {
 
    // Retrieve appropriate columns from font data
 
    for (col = 0; col < font.u8Width; col++)
 
    {
 
      column[col] = font.au8FontTable[((c - 32) * font.u8Width) + col];    // Get first column of appropriate character
 
    }
 
  }
 
  else
 
  {
 
    // Requested character is not available in this font ... send a space instead
 
    for (col = 0; col < font.u8Width; col++)
 
    {
 
      column[col] = 0xFF;    // Send solid space
 
    }
 
  }
 
 
  // Render each column
 
  uint16_t xoffset, yoffset;
 
  for (xoffset = 0; xoffset < font.u8Width; xoffset++)
 
  {
 
    for (yoffset = 0; yoffset < (font.u8Height + 1); yoffset++)
 
    {
 
      uint8_t bit = 0x00;
 
      bit = (column[xoffset] << (8 - (yoffset + 1)));     // Shift current row bit left
 
      bit = (bit >> 7);                     // Shift current row but right (results in 0x01 for black, and 0x00 for white)
 
      if (bit)
 
      {
 
        ssd1306_DrawPixel(x + xoffset, y + yoffset, 1);
 
      }
 
    }
 
  }
 
}
 
 
ssd1306_DrawString(uint8_t x, uint8_t y, const char *text, struct FONT_DEF font)
 
{
 
  uint8_t l;
 
  for (l = 0; l < strlen(text); l++)
 
  {
 
    ssd1306DrawChar(x + (l * (font.u8Width + 1)), y, text[l], font);
 
  }
 
}
 
 
*/
stm32l1xx_it.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * @file    stm32l1xx_it.c 
 
  * @author  MCD Application Team
 
  * @version V1.0.0
 
  * @date    29-July-2013
 
  * @brief   Main Interrupt Service Routines.
 
  *          This file provides template for all exceptions handler and 
 
  *          peripherals interrupt service routine.
 
  ******************************************************************************
 
  * @attention
 
  *
 
  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
 
  *
 
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 
  * You may not use this file except in compliance with the License.
 
  * You may obtain a copy of the License at:
 
  *
 
  *        http://www.st.com/software_license_agreement_liberty_v2
 
  *
 
  * Unless required by applicable law or agreed to in writing, software 
 
  * distributed under the License is distributed on an "AS IS" BASIS, 
 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  * See the License for the specific language governing permissions and
 
  * limitations under the License.
 
  *
 
  ******************************************************************************
 
  */
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "hw_config.h"
 
#include "stm32l1xx_it.h"
 
#include "main.h"
 
#include "usb_lib.h"
 
#include "usb_istr.h"
 
 
/** @addtogroup STM32L100C-Discovery_Demo
 
  * @{
 
  */
 
 
/* Private typedef -----------------------------------------------------------*/
 
/* Private define ------------------------------------------------------------*/
 
/* Private macro -------------------------------------------------------------*/
 
/* Private variables ---------------------------------------------------------*/
 
/* Private function prototypes -----------------------------------------------*/
 
/* Private functions ---------------------------------------------------------*/
 
 
/******************************************************************************/
 
/*            Cortex-M3 Processor Exceptions Handlers                         */
 
/******************************************************************************/
 
 
/**
 
  * @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 PendSVC exception.
 
  * @param  None
 
  * @retval None
 
  */
 
void PendSV_Handler(void)
 
{
 
}
 
 
/**
 
  * @brief  This function handles SysTick Handler.
 
  * @param  None
 
  * @retval None
 
  */
 
void SysTick_Handler(void)
 
{
 
  TimingDelay_Decrement();
 
}
 
 
 
 
 
 
 
/*******************************************************************************
 
* Function Name  : USB_IRQHandler
 
* Description    : This function handles USB Low Priority interrupts
 
*                  requests.
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)|| defined (STM32F37X)
 
void USB_LP_IRQHandler(void)
 
#else
 
void USB_LP_CAN1_RX0_IRQHandler(void)
 
#endif
 
{
 
  USB_Istr();
 
}
 
 
/*******************************************************************************
 
* Function Name  : USB_FS_WKUP_IRQHandler
 
* Description    : This function handles USB WakeUp interrupt request.
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
 
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS)
 
void USB_FS_WKUP_IRQHandler(void)
 
#else
 
void USBWakeUp_IRQHandler(void)
 
#endif
 
{
 
  EXTI_ClearITPendingBit(EXTI_Line18);
 
}
 
 
 
 
 
 
 
/******************************************************************************/
 
/*                 STM32L1xx Peripherals Interrupt Handlers                   */
 
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
 
/*  available peripheral interrupt handler's name please refer to the startup */
 
/*  file (startup_stm32l1xx_xx.s).                                            */
 
/******************************************************************************/
 
 
/**
 
  * @brief  This function handles PPP interrupt request.
 
  * @param  None
 
  * @retval None
 
  */
 
/*void PPP_IRQHandler(void)
 
{
 
}*/
 
 
/**
 
  * @}
 
  */ 
 
 
 
 
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
system_stm32l1xx.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * @file    system_stm32l1xx.c
 
  * @author  MCD Application Team
 
  * @version V1.2.0
 
  * @date    11-July-2014
 
  * @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
 
  *          This file contains the system clock configuration for STM32L1xx Ultra
 
  *          Low power devices, and is generated by the clock configuration 
 
  *          tool  STM32L1xx_Clock_Configuration_V1.2.0.xls
 
  *             
 
  * 1.  This file provides two functions and one global variable to be called from 
 
  *     user application:
 
  *      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
 
  *                      and Divider factors, AHB/APBx prescalers and Flash settings),
 
  *                      depending on the configuration made in the clock xls tool. 
 
  *                      This function is called at startup just after reset and 
 
  *                      before branch to main program. This call is made inside
 
  *                      the "startup_stm32l1xx_xx.s" file.
 
  *                        
 
  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
 
  *                                  by the user application to setup the SysTick 
 
  *                                  timer or configure other parameters.
 
  *                                     
 
  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
 
  *                                 be called whenever the core clock is changed
 
  *                                 during program execution.   
 
  *      
 
  * 2. After each device reset the MSI (2.1 MHz Range) is used as system clock source.
 
  *    Then SystemInit() function is called, in "startup_stm32l1xx_xx.s" file, to
 
  *    configure the system clock before to branch to main program.    
 
  *    
 
  * 3. If the system clock source selected by user fails to startup, the SystemInit()
 
  *    function will do nothing and MSI still used as system clock source. User can 
 
  *    add some code to deal with this issue inside the SetSysClock() function.       
 
  * 
 
  * 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define
 
  *    in "stm32l1xx.h" file. When HSE is used as system clock source, directly or
 
  *    through PLL, and you are using different crystal you have to adapt the HSE
 
  *    value to your own configuration.
 
  * 
 
  * 5. This file configures the system clock as follows:  
 
  *=============================================================================
 
  *                         System Clock Configuration
 
  *=============================================================================
 
  *        System Clock source          | PLL(HSE)
 
  *----------------------------------------------------------------------------- 
 
  *        SYSCLK                       | 32000000 Hz
 
  *----------------------------------------------------------------------------- 
 
  *        HCLK                         | 32000000 Hz
 
  *----------------------------------------------------------------------------- 
 
  *        AHB Prescaler                | 1
 
  *----------------------------------------------------------------------------- 
 
  *        APB1 Prescaler               | 1
 
  *----------------------------------------------------------------------------- 
 
  *        APB2 Prescaler               | 1
 
  *----------------------------------------------------------------------------- 
 
  *        HSE Frequency                | 4000000 Hz
 
  *----------------------------------------------------------------------------- 
 
  *        PLL DIV                      | 3
 
  *----------------------------------------------------------------------------- 
 
  *        PLL MUL                      | 24
 
  *----------------------------------------------------------------------------- 
 
  *        VDD                          | 3.3 V
 
  *----------------------------------------------------------------------------- 
 
  *        Vcore                        | 1.8 V (Range 1)
 
  *----------------------------------------------------------------------------- 
 
  *        Flash Latency                | 1 WS
 
  *----------------------------------------------------------------------------- 
 
  *        Require 48MHz for USB clock  | Enabled
 
  *----------------------------------------------------------------------------- 
 
  *=============================================================================
 
  * @attention
 
  *
 
  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
 
  *
 
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 
  * You may not use this file except in compliance with the License.
 
  * You may obtain a copy of the License at:
 
  *
 
  *        http://www.st.com/software_license_agreement_liberty_v2
 
  *
 
  * Unless required by applicable law or agreed to in writing, software 
 
  * distributed under the License is distributed on an "AS IS" BASIS, 
 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  * See the License for the specific language governing permissions and
 
  * limitations under the License.
 
  *
 
  ******************************************************************************
 
  */
 

	
 
/** @addtogroup CMSIS
 
  * @{
 
  */
 

	
 
/** @addtogroup stm32l1xx_system
 
  * @{
 
  */  
 
  
 
/** @addtogroup STM32L1xx_System_Private_Includes
 
  * @{
 
  */
 

	
 
#include "stm32l1xx.h"
 

	
 
/**
 
  * @}
 
  */
 

	
 
/** @addtogroup STM32L1xx_System_Private_TypesDefinitions
 
  * @{
 
  */
 

	
 
/**
 
  * @}
 
  */
 

	
 
/** @addtogroup STM32L1xx_System_Private_Defines
 
  * @{
 
  */
 

	
 
/*!< Uncomment the following line if you need to relocate your vector Table in
 
     Internal SRAM. */ 
 
/* #define VECT_TAB_SRAM */
 
#define VECT_TAB_OFFSET  0x0 /*!< Vector Table base offset field. 
 
                                  This value must be a multiple of 0x200. */
 
/**
 
  * @}
 
  */
 

	
 
/** @addtogroup STM32L1xx_System_Private_Macros
 
  * @{
 
  */
 

	
 
/**
 
  * @}
 
  */
 

	
 
/** @addtogroup STM32L1xx_System_Private_Variables
 
  * @{
 
  */
 
uint32_t SystemCoreClock    = 32000000;
 
__I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};
 
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
 

	
 
/**
 
  * @}
 
  */
 

	
 
/** @addtogroup STM32L1xx_System_Private_FunctionPrototypes
 
  * @{
 
  */
 

	
 
static void SetSysClock(void);
 

	
 
/**
 
  * @}
 
  */
 

	
 
/** @addtogroup STM32L1xx_System_Private_Functions
 
  * @{
 
  */
 

	
 
/**
 
  * @brief  Setup the microcontroller system.
 
  *         Initialize the Embedded Flash Interface, the PLL and update the 
 
  *         SystemCoreClock variable.
 
  * @param  None
 
  * @retval None
 
  */
 
void SystemInit (void)
 
{
 
  /*!< Set MSION bit */
 
  RCC->CR |= (uint32_t)0x00000100;
 

	
 
  /*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */
 
  RCC->CFGR &= (uint32_t)0x88FFC00C;
 
  
 
  /*!< Reset HSION, HSEON, CSSON and PLLON bits */
 
  RCC->CR &= (uint32_t)0xEEFEFFFE;
 

	
 
  /*!< Reset HSEBYP bit */
 
  RCC->CR &= (uint32_t)0xFFFBFFFF;
 

	
 
  /*!< Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */
 
  RCC->CFGR &= (uint32_t)0xFF02FFFF;
 

	
 
  /*!< Disable all interrupts */
 
  RCC->CIR = 0x00000000;
 

	
 
  /* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */
 
  SetSysClock();
 

	
 
#ifdef VECT_TAB_SRAM
 
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
 
#else
 
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
 
#endif
 
}
 

	
 
/**
 
  * @brief  Update SystemCoreClock according to Clock Register Values
 
  *         The SystemCoreClock variable contains the core clock (HCLK), it can
 
  *         be used by the user application to setup the SysTick timer or configure
 
  *         other parameters.
 
  *           
 
  * @note   Each time the core clock (HCLK) changes, this function must be called
 
  *         to update SystemCoreClock variable value. Otherwise, any configuration
 
  *         based on this variable will be incorrect.         
 
  *     
 
  * @note   - The system frequency computed by this function is not the real 
 
  *           frequency in the chip. It is calculated based on the predefined 
 
  *           constant and the selected clock source:
 
  *             
 
  *           - If SYSCLK source is MSI, SystemCoreClock will contain the MSI 
 
  *             value as defined by the MSI range.
 
  *                                   
 
  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
 
  *                                              
 
  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
 
  *                          
 
  *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 
 
  *             or HSI_VALUE(*) multiplied/divided by the PLL factors.
 
  *         
 
  *         (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value
 
  *             16 MHz) but the real value may vary depending on the variations
 
  *             in voltage and temperature.   
 
  *    
 
  *         (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value
 
  *              8 MHz), user has to ensure that HSE_VALUE is same as the real
 
  *              frequency of the crystal used. Otherwise, this function may
 
  *              have wrong result.
 
  *                
 
  *         - The result of this function could be not correct when using fractional
 
  *           value for HSE crystal.  
 
  * @param  None
 
  * @retval None
 
  */
 
void SystemCoreClockUpdate (void)
 
{
 
  uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, msirange = 0;
 

	
 
  /* Get SYSCLK source -------------------------------------------------------*/
 
  tmp = RCC->CFGR & RCC_CFGR_SWS;
 
  
 
  switch (tmp)
 
  {
 
    case 0x00:  /* MSI used as system clock */
 
      msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13;
 
      SystemCoreClock = (32768 * (1 << (msirange + 1)));
 
      break;
 
    case 0x04:  /* HSI used as system clock */
 
      SystemCoreClock = HSI_VALUE;
 
      break;
 
    case 0x08:  /* HSE used as system clock */
 
      SystemCoreClock = HSE_VALUE;
 
      break;
 
    case 0x0C:  /* PLL used as system clock */
 
      /* Get PLL clock source and multiplication factor ----------------------*/
 
      pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;
 
      plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;
 
      pllmul = PLLMulTable[(pllmul >> 18)];
 
      plldiv = (plldiv >> 22) + 1;
 
      
 
      pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
 

	
 
      if (pllsource == 0x00)
 
      {
 
        /* HSI oscillator clock selected as PLL clock entry */
 
        SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv);
 
      }
 
      else
 
      {
 
        /* HSE selected as PLL clock entry */
 
        SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv);
 
      }
 
      break;
 
    default: /* MSI used as system clock */
 
      msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13;
 
      SystemCoreClock = (32768 * (1 << (msirange + 1)));
 
      break;
 
  }
 
  /* Compute HCLK clock frequency --------------------------------------------*/
 
  /* Get HCLK prescaler */
 
  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
 
  /* HCLK clock frequency */
 
  SystemCoreClock >>= tmp;
 
}
 

	
 
/**
 
  * @brief  Configures the System clock frequency, AHB/APBx prescalers and Flash 
 
  *         settings.
 
  * @note   This function should be called only once the RCC clock configuration  
 
  *         is reset to the default reset state (done in SystemInit() function).             
 
  * @param  None
 
  * @retval None
 
  */
 
static void SetSysClock(void)
 
{
 
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
 
  
 
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
 
  /* Enable HSE */
 
  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 
 
 
  /* Wait till HSE is ready and if Time out is reached exit */
 
  do
 
  {
 
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
 
    StartUpCounter++;
 
  } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
 

	
 
  if ((RCC->CR & RCC_CR_HSERDY) != RESET)
 
  {
 
    HSEStatus = (uint32_t)0x01;
 
  }
 
  else
 
  {
 
    HSEStatus = (uint32_t)0x00;
 
  }
 
  
 
  if (HSEStatus == (uint32_t)0x01)
 
  {
 
    /* Enable 64-bit access */
 
    FLASH->ACR |= FLASH_ACR_ACC64;
 
    
 
    /* Enable Prefetch Buffer */
 
    FLASH->ACR |= FLASH_ACR_PRFTEN;
 

	
 
    /* Flash 1 wait state */
 
    FLASH->ACR |= FLASH_ACR_LATENCY;
 
    
 
    /* Power enable */
 
    RCC->APB1ENR |= RCC_APB1ENR_PWREN;
 
  
 
    /* Select the Voltage Range 1 (1.8 V) */
 
    PWR->CR = PWR_CR_VOS_0;
 
  
 
    /* Wait Until the Voltage Regulator is ready */
 
    while((PWR->CSR & PWR_CSR_VOSF) != RESET)
 
    {
 
    }
 
        
 
    /* HCLK = SYSCLK /1*/
 
    RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
 
  
 
    /* PCLK2 = HCLK /1*/
 
    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
 
    
 
    /* PCLK1 = HCLK /1*/
 
    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
 
    
 
    /*  PLL configuration */
 
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL |
 
                                        RCC_CFGR_PLLDIV));
 
    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMUL24 | RCC_CFGR_PLLDIV3);
 

	
 
    /* Enable PLL */
 
    RCC->CR |= RCC_CR_PLLON;
 

	
 
    /* Wait till PLL is ready */
 
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
 
    {
 
    }
 
        
 
    /* Select PLL as system clock source */
 
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
 
    RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
 

	
 
    /* Wait till PLL is used as system clock source */
 
    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
 
    {
 
    }
 
  }
 
  else
 
  {
 
	while(1);
 
//	while(1);
 
    /* If HSE fails to start-up, the application will have wrong clock
 
       configuration. User can add here some code to deal with this error */
 
  }
 
}
 

	
 
/**
 
  * @}
 
  */
 

	
 
/**
 
  * @}
 
  */
 

	
 
/**
 
  * @}
 
  */
 

	
 
/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
 

	
0 comments (0 inline, 0 general)