Files @ 6982c8ddef15
Branch filter:

Location: therm/Libraries/u8glib/u8g_arm.c - annotation

Ethan Zonca
Add graphics lib
uint8_t u8g_com_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{

  switch(msg)
  {
    case U8G_COM_MSG_STOP:
      break; //do nothing...

    case U8G_COM_MSG_INIT:
      i2c_init(); //inits the i2c hardware, gpios and timers
      u8g_MicroDelay();      
      break;

    case U8G_COM_MSG_ADDRESS: 
      //the control byte switches the mode on the device and is set here
      if (arg_val == 0)
      {
    	  control = 0;
      }
      else
      {
    	  control = 0x40;
      }
      u8g_10MicroDelay();
     break;

    case U8G_COM_MSG_RESET:
      //pin 9 is my reset pin
      GPIO_WriteBit(GPIOB, GPIO_Pin_9, arg_val);
      u8g_10MicroDelay();
      break;

    case U8G_COM_MSG_WRITE_BYTE:
      //simple: just write one byte
      i2c_out(arg_val);
      u8g_MicroDelay();
      break;

    case U8G_COM_MSG_WRITE_SEQ:
    case U8G_COM_MSG_WRITE_SEQ_P:
      {
        register uint8_t *ptr = arg_ptr;
        //send the control byte (to switch from command to data mode)
        I2C_start(SSD1306_I2C_ADDRESS, I2C_Direction_Transmitter);
    	I2C_SendData(I2C2, control);
    	while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

        //now send the rest of data
        while( arg_val > 0 )
        {
        	I2C_SendData(I2C2, *ptr++);
        	arg_val--;
        	while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
        }
        //done
    	I2C_stop();
        u8g_MicroDelay();
      }
      break;

  }
  return 1;
}