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_atmega_sw_spi.c
00001 /* 00002 00003 u8g_com_atmega_sw_spi.c 00004 00005 Universal 8bit Graphics Library 00006 00007 Copyright (c) 2012, olikraus@gmail.com 00008 All rights reserved. 00009 00010 Redistribution and use in source and binary forms, with or without modification, 00011 are permitted provided that the following conditions are met: 00012 00013 * Redistributions of source code must retain the above copyright notice, this list 00014 of conditions and the following disclaimer. 00015 00016 * Redistributions in binary form must reproduce the above copyright notice, this 00017 list of conditions and the following disclaimer in the documentation and/or other 00018 materials provided with the distribution. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00021 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00022 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00025 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00027 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00030 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00031 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00032 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 00035 */ 00036 00037 #include "u8g.h" 00038 00039 #if defined(__AVR__) 00040 00041 static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 00042 static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 00043 { 00044 uint8_t i = 8; 00045 do 00046 { 00047 u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 00048 val <<= 1; 00049 u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 00050 u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 00051 u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 00052 u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 00053 i--; 00054 } while( i != 0 ); 00055 } 00056 00057 uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00058 { 00059 switch(msg) 00060 { 00061 case U8G_COM_MSG_INIT: 00062 u8g_SetPIOutput(u8g, U8G_PI_SCK); 00063 u8g_SetPIOutput(u8g, U8G_PI_MOSI); 00064 u8g_SetPIOutput(u8g, U8G_PI_A0); 00065 u8g_SetPIOutput(u8g, U8G_PI_CS); 00066 u8g_SetPIOutput(u8g, U8G_PI_RESET); 00067 00068 u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 00069 u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 00070 u8g_SetPILevel(u8g, U8G_PI_CS, 1 ); 00071 u8g_SetPILevel(u8g, U8G_PI_A0, 0); 00072 break; 00073 00074 case U8G_COM_MSG_STOP: 00075 break; 00076 00077 case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 00078 u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 00079 break; 00080 00081 case U8G_COM_MSG_CHIP_SELECT: 00082 00083 if ( arg_val == 0 ) 00084 { 00085 /* disable */ 00086 u8g_SetPILevel(u8g, U8G_PI_CS, 1); 00087 } 00088 else 00089 { 00090 u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 00091 /* enable */ 00092 u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */ 00093 } 00094 break; 00095 00096 case U8G_COM_MSG_RESET: 00097 u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 00098 break; 00099 00100 00101 case U8G_COM_MSG_WRITE_BYTE: 00102 u8g_atmega_sw_spi_shift_out(u8g, arg_val); 00103 break; 00104 00105 case U8G_COM_MSG_WRITE_SEQ: 00106 { 00107 register uint8_t *ptr = arg_ptr; 00108 while( arg_val > 0 ) 00109 { 00110 u8g_atmega_sw_spi_shift_out(u8g, *ptr++); 00111 arg_val--; 00112 } 00113 } 00114 break; 00115 00116 case U8G_COM_MSG_WRITE_SEQ_P: 00117 { 00118 register uint8_t *ptr = arg_ptr; 00119 while( arg_val > 0 ) 00120 { 00121 u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr)); 00122 ptr++; 00123 arg_val--; 00124 } 00125 } 00126 break; 00127 } 00128 return 1; 00129 } 00130 00131 #else 00132 00133 00134 uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 00135 { 00136 return 1; 00137 } 00138 00139 00140 #endif 00141 00142
Generated on Tue Jul 12 2022 17:30:57 by
1.7.2