Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
u8g_com_arduino_ssd_i2c.c
00001 /* 00002 00003 u8g_com_arduino_ssd_i2c.c 00004 00005 com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant 00006 I2C protocol 00007 00008 ToDo: Rename this to u8g_com_avr_ssd_i2c.c 00009 00010 Universal 8bit Graphics Library 00011 00012 Copyright (c) 2012, olikraus@gmail.com 00013 All rights reserved. 00014 00015 Redistribution and use in source and binary forms, with or without modification, 00016 are permitted provided that the following conditions are met: 00017 00018 * Redistributions of source code must retain the above copyright notice, this list 00019 of conditions and the following disclaimer. 00020 00021 * Redistributions in binary form must reproduce the above copyright notice, this 00022 list of conditions and the following disclaimer in the documentation and/or other 00023 materials provided with the distribution. 00024 00025 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00026 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00027 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00028 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00029 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00030 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00031 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00032 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00033 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00034 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00035 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00037 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 00039 Special pin usage: 00040 U8G_PI_I2C_OPTION additional options 00041 U8G_PI_A0_STATE used to store the last value of the command/data register selection 00042 U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device 00043 U8G_PI_SCL clock line (NOT USED) 00044 U8G_PI_SDA data line (NOT USED) 00045 00046 U8G_PI_RESET reset line (currently disabled, see below) 00047 00048 Protocol: 00049 SLA, Cmd/Data Selection, Arguments 00050 The command/data register is selected by a special instruction byte, which is sent after SLA 00051 00052 The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode 00053 */ 00054 00055 #include "u8g.h" 00056 00057 #define I2C_SLA (0x3c*2) 00058 //#define I2C_CMD_MODE 0x080 00059 #define I2C_CMD_MODE 0x000 00060 #define I2C_DATA_MODE 0x040 00061 00062 #if defined(U8G_WITH_PINLIST) 00063 00064 uint8_t u8g_com_arduino_ssd_start_sequence(u8g_t *u8g) 00065 { 00066 /* are we requested to set the a0 state? */ 00067 if ( u8g->pin_list[U8G_PI_SET_A0] == 0 ) 00068 return 1; 00069 00070 /* setup bus, might be a repeated start */ 00071 if ( u8g_i2c_start(I2C_SLA) == 0 ) 00072 return 0; 00073 if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 ) 00074 { 00075 if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 ) 00076 return 0; 00077 } 00078 else 00079 { 00080 if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 ) 00081 return 0; 00082 } 00083 00084 00085 u8g->pin_list[U8G_PI_SET_A0] = 0; 00086 return 1; 00087 } 00088 00089 uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00090 { 00091 switch(msg) 00092 { 00093 case U8G_COM_MSG_INIT: 00094 //u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH); 00095 //u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH); 00096 //u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */ 00097 00098 u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]); 00099 00100 break; 00101 00102 case U8G_COM_MSG_STOP: 00103 break; 00104 00105 case U8G_COM_MSG_RESET: 00106 /* Currently disabled, but it could be enable. Previous restrictions have been removed */ 00107 /* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */ 00108 break; 00109 00110 case U8G_COM_MSG_CHIP_SELECT: 00111 u8g->pin_list[U8G_PI_A0_STATE] = 0; 00112 u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */ 00113 if ( arg_val == 0 ) 00114 { 00115 /* disable chip, send stop condition */ 00116 u8g_i2c_stop(); 00117 } 00118 else 00119 { 00120 /* enable, do nothing: any byte writing will trigger the i2c start */ 00121 } 00122 break; 00123 00124 case U8G_COM_MSG_WRITE_BYTE: 00125 //u8g->pin_list[U8G_PI_SET_A0] = 1; 00126 if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 ) 00127 return u8g_i2c_stop(), 0; 00128 if ( u8g_i2c_send_byte(arg_val) == 0 ) 00129 return u8g_i2c_stop(), 0; 00130 // u8g_i2c_stop(); 00131 break; 00132 00133 case U8G_COM_MSG_WRITE_SEQ: 00134 //u8g->pin_list[U8G_PI_SET_A0] = 1; 00135 if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 ) 00136 return u8g_i2c_stop(), 0; 00137 { 00138 register uint8_t *ptr = arg_ptr; 00139 while( arg_val > 0 ) 00140 { 00141 if ( u8g_i2c_send_byte(*ptr++) == 0 ) 00142 return u8g_i2c_stop(), 0; 00143 arg_val--; 00144 } 00145 } 00146 // u8g_i2c_stop(); 00147 break; 00148 00149 case U8G_COM_MSG_WRITE_SEQ_P: 00150 //u8g->pin_list[U8G_PI_SET_A0] = 1; 00151 if ( u8g_com_arduino_ssd_start_sequence(u8g) == 0 ) 00152 return u8g_i2c_stop(), 0; 00153 { 00154 register uint8_t *ptr = arg_ptr; 00155 while( arg_val > 0 ) 00156 { 00157 if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 ) 00158 return 0; 00159 ptr++; 00160 arg_val--; 00161 } 00162 } 00163 // u8g_i2c_stop(); 00164 break; 00165 00166 case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 00167 u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 00168 u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */ 00169 00170 #ifdef OLD_CODE 00171 if ( i2c_state != 0 ) 00172 { 00173 u8g_i2c_stop(); 00174 i2c_state = 0; 00175 } 00176 00177 if ( u8g_com_arduino_ssd_start_sequence(arg_val) == 0 ) 00178 return 0; 00179 00180 /* setup bus, might be a repeated start */ 00181 /* 00182 if ( u8g_i2c_start(I2C_SLA) == 0 ) 00183 return 0; 00184 if ( arg_val == 0 ) 00185 { 00186 i2c_state = 1; 00187 00188 if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 ) 00189 return 0; 00190 } 00191 else 00192 { 00193 i2c_state = 2; 00194 if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 ) 00195 return 0; 00196 } 00197 */ 00198 #endif 00199 break; 00200 } 00201 return 1; 00202 } 00203 00204 #else /* defined(U8G_WITH_PINLIST) */ 00205 00206 uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00207 { 00208 return 1; 00209 } 00210 00211 #endif /* defined(U8G_WITH_PINLIST) */ 00212 00213
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2