Changeset - 577e97ae4dc1
[Not reviewed]
cortex-f0
0 4 0
Ethan Zonca - 10 years ago 2015-01-03 00:16:55
ez@ethanzonca.com
Remove discovery includes. Should probably just include _conf.h or something instead.
4 files changed with 0 insertions and 4 deletions:
0 comments (0 inline, 0 general)
eeprom_min.c
Show inline comments
 
#include "stm32l100c_discovery.h"
 

	
 
void Minimal_EEPROM_Unlock(void)
 
{
 
  if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
 
  {
 
    /* Unlocking the Data memory and FLASH_PECR register access*/
 
    FLASH->PEKEYR = FLASH_PEKEY1;
 
    FLASH->PEKEYR = FLASH_PEKEY2;
 
  }
 
}
 

	
 
void Minimal_EEPROM_Lock(void)
 
{
 
  /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */
 
  FLASH->PECR |= FLASH_PECR_PELOCK;
 
}
 

	
 
FLASH_Status Minimal_FLASH_GetStatus(void)
 
{
 
  FLASH_Status FLASHstatus = FLASH_COMPLETE;
 

	
 
  if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
 
  {
 
    FLASHstatus = FLASH_BUSY;
 
  }
 
  else
 
  {
 
    if((FLASH->SR & (uint32_t)FLASH_FLAG_WRPERR)!= (uint32_t)0x00)
 
    {
 
      FLASHstatus = FLASH_ERROR_WRP;
 
    }
 
    else
 
    {
 
      if((FLASH->SR & (uint32_t)0x1E00) != (uint32_t)0x00)
 
      {
 
        FLASHstatus = FLASH_ERROR_PROGRAM;
 
      }
 
      else
 
      {
 
        FLASHstatus = FLASH_COMPLETE;
 
      }
 
    }
 
  }
 
  /* Return the FLASH Status */
 
  return FLASHstatus;
 
}
 

	
 
FLASH_Status Minimal_FLASH_WaitForLastOperation(uint32_t Timeout)
 
{
 
  __IO FLASH_Status status = FLASH_COMPLETE;
 

	
 
  /* Check for the FLASH Status */
 
  status = Minimal_FLASH_GetStatus();
 

	
 
  /* Wait for a FLASH operation to complete or a TIMEOUT to occur */
 
  while((status == FLASH_BUSY) && (Timeout != 0x00))
 
  {
 
    status = Minimal_FLASH_GetStatus();
 
    Timeout--;
 
  }
 

	
 
  if(Timeout == 0x00 )
 
  {
 
    status = FLASH_TIMEOUT;
 
  }
 
  /* Return the operation status */
 
  return status;
 
}
 

	
 

	
 
void Minimal_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)
 
{
 
  // Wait for last operation to be completed 
 
  FLASH_Status status = FLASH_COMPLETE;
 
  status = Minimal_FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
 

	
 
  if(status == FLASH_COMPLETE)
 
  {
 
    *(__IO uint32_t *)Address = Data;
 

	
 
    // Wait for last operation to be completed 
 
    status = Minimal_FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
 
  }
 
  // Return the Write Status 
 
  return status;
 
}
 

	
gpio.c
Show inline comments
 
#include "stm32l100c_discovery.h"
 
#include "gpio.h"
 
#include "config.h"
 

	
 
extern volatile uint32_t ticks;
 

	
 
// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
 
uint32_t change_time_reset = 0;
 

	
 
void user_input(uint16_t* to_modify)
 
{
 
    if(CHANGE_ELAPSED) {
 
        if(!GPIO_ReadInputDataBit(SW_UP) ) {
 
            CHANGE_RESET;
 
            (*to_modify)++;
 
        }
 
        else if(!GPIO_ReadInputDataBit(SW_DOWN) && (*to_modify) > 0) {
 
            CHANGE_RESET;
 
            (*to_modify)--;
 
        }
 
    }
 
}
 

	
 

	
 
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
 
  */
 

	
spi.c
Show inline comments
 
#include "stm32l100c_discovery.h"
 

	
 
void init_spi(void)
 
{
 
    SPI_InitTypeDef  SPI_InitStructure;
 

	
 
    // OLED IC
 
    SPI_Cmd(SPI1, DISABLE); 
 
    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_4;
 
    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_Cmd(SPI2, DISABLE); 
 
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
 
    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
 
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
 
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
 
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
 
    SPI_InitStructure.SPI_CRCPolynomial = 7;
 
    SPI_Init(SPI2, &SPI_InitStructure);
 
    SPI_Cmd(SPI2, ENABLE);           /* Enable the SPI */
 
}
 

	
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
ssd1306.c
Show inline comments
 
#include "stm32l100c_discovery.h"
 
#include "ssd1306.h"
 
 
// Write command to OLED
 
void WriteCommand(unsigned char command)
 
{
 
  SSD_A0_Low();
 
  SPI_SendByte(command);
 
  SPI_Wait();
 
}
 
 
// Write data to OLED
 
void WriteData(unsigned char data)
 
{
 
  SSD_A0_High();
 
  SPI_SendByte(data);
 
  SPI_Wait();
 
}
 
 
// Initialize OLED
 
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 (normal)
 
  WriteCommand(0xA0); // segremap (flip)
 
//  WriteCommand(0xC8); // comscandec (normal)
 
  WriteCommand(0xC0); // comscandec (flip)
 
  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 
 
}
 
 
 
// Times New Roman font
 
const char fontData[240][5] =
 
{                                       // Refer to "Times New Roman" Font Database
 
                                        //   Basic Characters
 
    {0x00,0x00,0x00,0x00,0x00},         //   (  0)    - 0x0020 No-Break Space
 
    {0x00,0x00,0x4F,0x00,0x00},         //   (  1)  ! - 0x0021 Exclamation Mark
 
    {0x00,0x07,0x00,0x07,0x00},         //   (  2)  " - 0x0022 Quotation Mark
 
    {0x14,0x7F,0x14,0x7F,0x14},         //   (  3)  # - 0x0023 Number Sign
 
    {0x24,0x2A,0x7F,0x2A,0x12},         //   (  4)  $ - 0x0024 Dollar Sign
 
    {0x23,0x13,0x08,0x64,0x62},         //   (  5)  % - 0x0025 Percent Sign
 
    {0x36,0x49,0x55,0x22,0x50},         //   (  6)  & - 0x0026 Ampersand
 
    {0x00,0x05,0x03,0x00,0x00},         //   (  7)  ' - 0x0027 Apostrophe
 
    {0x00,0x1C,0x22,0x41,0x00},         //   (  8)  ( - 0x0028 Left Parenthesis
 
    {0x00,0x41,0x22,0x1C,0x00},         //   (  9)  ) - 0x0029 Right Parenthesis
 
    {0x14,0x08,0x3E,0x08,0x14},         //   ( 10)  * - 0x002A Asterisk
 
    {0x08,0x08,0x3E,0x08,0x08},         //   ( 11)  + - 0x002B Plus Sign
 
    {0x00,0x50,0x30,0x00,0x00},         //   ( 12)  , - 0x002C Comma
 
    {0x08,0x08,0x08,0x08,0x08},         //   ( 13)  - - 0x002D Hyphen-Minus
 
    {0x00,0x60,0x60,0x00,0x00},         //   ( 14)  . - 0x002E Full Stop
 
    {0x20,0x10,0x08,0x04,0x02},         //   ( 15)  / - 0x002F Solidus
 
    {0x3E,0x51,0x49,0x45,0x3E},         //   ( 16)  0 - 0x0030 Digit Zero
 
    {0x00,0x42,0x7F,0x40,0x00},         //   ( 17)  1 - 0x0031 Digit One
 
    {0x42,0x61,0x51,0x49,0x46},         //   ( 18)  2 - 0x0032 Digit Two
 
    {0x21,0x41,0x45,0x4B,0x31},         //   ( 19)  3 - 0x0033 Digit Three
 
    {0x18,0x14,0x12,0x7F,0x10},         //   ( 20)  4 - 0x0034 Digit Four
 
    {0x27,0x45,0x45,0x45,0x39},         //   ( 21)  5 - 0x0035 Digit Five
 
    {0x3C,0x4A,0x49,0x49,0x30},         //   ( 22)  6 - 0x0036 Digit Six
 
    {0x01,0x71,0x09,0x05,0x03},         //   ( 23)  7 - 0x0037 Digit Seven
 
    {0x36,0x49,0x49,0x49,0x36},         //   ( 24)  8 - 0x0038 Digit Eight
 
    {0x06,0x49,0x49,0x29,0x1E},         //   ( 25)  9 - 0x0039 Dight Nine
 
    {0x00,0x36,0x36,0x00,0x00},         //   ( 26)  : - 0x003A Colon
 
    {0x00,0x56,0x36,0x00,0x00},         //   ( 27)  ; - 0x003B Semicolon
 
    {0x08,0x14,0x22,0x41,0x00},         //   ( 28)  < - 0x003C Less-Than Sign
 
    {0x14,0x14,0x14,0x14,0x14},         //   ( 29)  = - 0x003D Equals Sign
 
    {0x00,0x41,0x22,0x14,0x08},         //   ( 30)  > - 0x003E Greater-Than Sign
 
    {0x02,0x01,0x51,0x09,0x06},         //   ( 31)  ? - 0x003F Question Mark
0 comments (0 inline, 0 general)