Changeset - c31e71728728
[Not reviewed]
default
0 4 0
Ethan Zonca - 10 years ago 2014-08-13 23:11:50
ez@ethanzonca.com
Try getting block writing working. Also start modifying USB library. Looks like we may need to transition to a fresh USBlib download, this has freaky defines.
4 files changed with 32 insertions and 65 deletions:
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -30,63 +30,64 @@ void machine();
 
 
int main(void)
 
{
 
 
    // Init clocks
 
    SystemInit();
 
 
    init_gpio();
 
 
    Set_USBClock();
 
    USB_Interrupts_Config();
 
    GPIO_SetBits(LED_POWER);
 
    //USB_Init(); // freezes here... maybe clock issue?
 
    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(3,3,1);
 
    ssd1306_DrawPoint(5,5,0);
 
 
 
    while(1)
 
   {  
 
        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);
 
//        SPI_I2S_SendData(SPI2,0xFA);
 
//        SPI_I2S_SendData(SPI1,0xFA);
 
 
        if(!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_3)) {
 
            GPIO_ToggleBits(LED_STAT);
 
        }
 
 
        GPIO_SetBits(LED_POWER);
 
        Delay(50);
 
        GPIO_ResetBits(LED_POWER);
 
        Delay(50);
 
    }
 
}
 
 
@@ -95,25 +96,25 @@ 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 = SPI_I2S_ReceiveData(SPI2);
 
    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;
platform_config.h
Show inline comments
 
@@ -87,78 +87,22 @@
 
#define         ID2          (0x1FFFF7B0)
 
#define         ID3          (0x1FFFF7B4)
 
 
#else /*STM32F1x*/
 
 
#define         ID1          (0x1FFFF7E8)
 
#define         ID2          (0x1FFFF7EC)
 
#define         ID3          (0x1FFFF7F0)
 
 
#endif
 
 
/* Define the STM32F10x hardware depending on the used evaluation board */
 
#ifdef USE_STM3210B_EVAL
 
  #define USB_DISCONNECT                      GPIOD  
 
  #define USB_DISCONNECT_PIN                  GPIO_Pin_9
 
  #define RCC_APB2Periph_GPIO_DISCONNECT      RCC_APB2Periph_GPIOD
 
  #define EVAL_COM1_IRQHandler                USART1_IRQHandler 
 
 
#elif defined (USE_STM3210E_EVAL)
 
  #define USB_DISCONNECT                      GPIOB  
 
  #define USB_DISCONNECT_PIN                  GPIO_Pin_14
 
  #define RCC_APB2Periph_GPIO_DISCONNECT      RCC_APB2Periph_GPIOB
 
  #define EVAL_COM1_IRQHandler                USART1_IRQHandler 
 
 
 
 
#elif defined (USE_STM32L152_EVAL) || defined (USE_STM32L152D_EVAL)
 
 /* 
 
   For STM32L15xx devices it is possible to use the internal USB pullup
 
   controlled by register SYSCFG_PMC (refer to RM0038 reference manual for
 
   more details).
 
   It is also possible to use external pullup (and disable the internal pullup)
 
   by setting the define USB_USE_EXTERNAL_PULLUP in file platform_config.h
 
   and configuring the right pin to be used for the external pull up configuration.
 
   To have more details on how to use an external pull up, please refer to 
 
   STM3210E-EVAL evaluation board manuals.
 
   */
 
 /* Uncomment the following define to use an external pull up instead of the 
 
    integrated STM32L15xx internal pull up. In this case make sure to set up
 
    correctly the external required hardware and the GPIO defines below.*/
 
/* #define USB_USE_EXTERNAL_PULLUP */
 
 
 #if !defined(USB_USE_EXTERNAL_PULLUP)
 
  #define STM32L15_USB_CONNECT                SYSCFG_USBPuCmd(ENABLE)
 
  #define STM32L15_USB_DISCONNECT             SYSCFG_USBPuCmd(DISABLE)
 
 
 #elif defined(USB_USE_EXTERNAL_PULLUP)
 
  /* PA0 is chosen just as illustrating example, you should modify the defines
 
    below according to your hardware configuration. */ 
 
  #define USB_DISCONNECT                      GPIOA
 
  #define USB_DISCONNECT_PIN                  GPIO_Pin_0
 
  #define RCC_AHBPeriph_GPIO_DISCONNECT       RCC_AHBPeriph_GPIOA
 
  #define STM32L15_USB_CONNECT                GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
 
  #define STM32L15_USB_DISCONNECT             GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
 
 #endif /* USB_USE_EXTERNAL_PULLUP */
 
 
#elif defined (USE_STM32373C_EVAL)
 
  #define USB_DISCONNECT                      GPIOC  
 
  #define USB_DISCONNECT_PIN                  GPIO_Pin_5
 
  #define RCC_AHBPeriph_GPIO_DISCONNECT       RCC_AHBPeriph_GPIOC
 
 
#elif defined (USE_STM32303C_EVAL)
 
  #define USB_DISCONNECT                      GPIOB  
 
  #define USB_DISCONNECT_PIN                  GPIO_Pin_8
 
  #define RCC_AHBPeriph_GPIO_DISCONNECT       RCC_AHBPeriph_GPIOB
 
#endif /* USE_STM3210B_EVAL */
 
 
#if defined (USE_STM32L152_EVAL) || (USE_STM32373C_EVAL)
 
 #define EVAL_COM1_IRQHandler                USART2_IRQHandler
 
#elif defined (USE_STM32L152D_EVAL) || (USE_STM32303C_EVAL)
 
 #define EVAL_COM1_IRQHandler              USART1_IRQHandler
 
#endif
 
#define USB_DISCONNECT                      GPIOA  
 
#define USB_DISCONNECT_PIN                  GPIO_Pin_10
 
#define RCC_APB2Periph_GPIO_DISCONNECT      RCC_APB2Periph_GPIOA
 
 
/* Exported macro ------------------------------------------------------------*/
 
/* Exported functions ------------------------------------------------------- */
 
 
#endif /* __PLATFORM_CONFIG_H */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ssd1306.c
Show inline comments
 
@@ -83,25 +83,25 @@ void ssd1306_Init(void)
 
 
  /* Generate a reset */
 
  SSD_Reset_Low();
 
  uint32_t i;
 
  for(i=5000; i>1; i--) 
 
  SSD_Reset_High();
 
  
 
  /*************************************************
 
  // ssd1306 Initialization Command
 
  *************************************************/
 
  // Lower Column Address
 
  WriteCommand(0x00); /* Set Lower Column Address */
 
  GPIO_SetBits(GPIOA,GPIO_Pin_15);
 
  GPIO_SetBits(GPIOA,GPIO_Pin_15);//turn on status LED
 
  // High Column Address
 
  WriteCommand(0x10); /* Set Higher Column Address*/
 
  // 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*/
 
@@ -155,24 +155,45 @@ void ssd1306_Init(void)
 
  WriteCommand(0x10);
 
  
 
  /* Turn on the controller */
 
  pre_on = ssd1306_ON();
 
//  // Set Charge pump
 
//  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++)
 
    WriteData(ssd1306_Buffer[i]);
 
}
 
 
 
/*******************************************************************************
 
* 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;
 
}
ssd1306.h
Show inline comments
 
@@ -4,14 +4,15 @@
 
 
void  ssd1306_Init(void);
 
void  StartPageTransfer(void);
 
extern  const DeviceProp  ssd1306_Prop;
 
unsigned long ssd1306_DrawBlock(Pos_t x, Pos_t y, Pos_t cx, Pos_t cy, const unsigned char* data);
 
unsigned long ssd1306_IsOn(void);
 
unsigned long ssd1306_TurnOff(void);
 
unsigned long ssd1306_TurnOn(void);
 
unsigned char ssd1306_SetContrast(unsigned char contrast);
 
unsigned char ssd1306_GetContrast();
 
unsigned char* ssd1306_GetBuffer();
 
unsigned long ssd1306_DrawPoint(Pos_t x, Pos_t y, Color_t color);
 
void ssd1306_block_write(void);
 
 
#endif
0 comments (0 inline, 0 general)