ArduinoAddons
Arduino_0.xx
Gen6
Gen7
Sanguino
hardware
libraries
LiquidCrystal
SPI
U8glib
examples
utility
chessengine.c
u8g.h
u8g_bitmap.c
u8g_circle.c
u8g_clip.c
u8g_com_api.c
u8g_com_api_16gr.c
u8g_com_arduino_common.c
u8g_com_arduino_fast_parallel.c
u8g_com_arduino_hw_spi.c
u8g_com_arduino_no_en_parallel.c
u8g_com_arduino_parallel.c
u8g_com_arduino_port_d_wr.c
u8g_com_arduino_ssd_i2c.c
u8g_com_arduino_st7920_hw_spi.c
u8g_com_arduino_st7920_spi.c
u8g_com_arduino_std_sw_spi.c
u8g_com_arduino_sw_spi.c
u8g_com_arduino_t6963.c
u8g_com_atmega_hw_spi.c
u8g_com_atmega_parallel.c
u8g_com_atmega_st7920_hw_spi.c
u8g_com_atmega_st7920_spi.c
u8g_com_atmega_sw_spi.c
u8g_com_i2c.c
u8g_com_io.c
u8g_com_null.c
u8g_cursor.c
u8g_delay.c
u8g_dev_flipdisc_2x7.c
u8g_dev_gprof.c
u8g_dev_ili9325d_320x240.c
u8g_dev_ks0108_128x64.c
u8g_dev_lc7981_160x80.c
u8g_dev_lc7981_240x128.c
u8g_dev_lc7981_240x64.c
u8g_dev_lc7981_320x64.c
u8g_dev_null.c
u8g_dev_pcd8544_84x48.c
u8g_dev_pcf8812_96x65.c
u8g_dev_sbn1661_122x32.c
u8g_dev_ssd1306_128x32.c
u8g_dev_ssd1306_128x64.c
u8g_dev_ssd1309_128x64.c
u8g_dev_ssd1322_nhd31oled_bw.c
u8g_dev_ssd1322_nhd31oled_gr.c
u8g_dev_ssd1325_nhd27oled_bw.c
u8g_dev_ssd1325_nhd27oled_bw_new.c
u8g_dev_ssd1325_nhd27oled_gr.c
u8g_dev_ssd1325_nhd27oled_gr_new.c
u8g_dev_ssd1327_96x96_gr.c
u8g_dev_st7565_64128n.c
u8g_dev_st7565_dogm128.c
u8g_dev_st7565_dogm132.c
u8g_dev_st7565_lm6059.c
u8g_dev_st7565_lm6063.c
u8g_dev_st7565_nhd_c12832.c
u8g_dev_st7565_nhd_c12864.c
u8g_dev_st7687_c144mvgd.c
u8g_dev_st7920_128x64.c
u8g_dev_st7920_192x32.c
u8g_dev_st7920_202x32.c
u8g_dev_t6963_128x64.c
u8g_dev_t6963_240x128.c
u8g_dev_t6963_240x64.c
u8g_dev_tls8204_84x48.c
u8g_dev_uc1610_dogxl160.c
u8g_dev_uc1701_dogs102.c
u8g_dev_uc1701_mini12864.c
u8g_ellipse.c
u8g_font.c
u8g_font_data.c
u8g_line.c
u8g_ll_api.c
u8g_page.c
u8g_pb.c
u8g_pb14v1.c
u8g_pb16h1.c
u8g_pb16h2.c
u8g_pb16v1.c
u8g_pb16v2.c
u8g_pb32h1.c
u8g_pb8h1.c
u8g_pb8h1f.c
u8g_pb8h2.c
u8g_pb8h8.c
u8g_pb8v1.c
u8g_pb8v2.c
u8g_rect.c
u8g_rot.c
u8g_scale.c
u8g_state.c
u8g_u16toa.c
u8g_u8toa.c
u8g_virtual_screen.c
ChangeLog
INSTALL.TXT
U8glib.cpp
U8glib.h
license.txt
Arduino_1.0.x
Arduino_1.5.x
Arduino_1.x.x
Documentation
Marlin
.gitignore
.travis.yml
README.md
216 lines
4.7 KiB
C
216 lines
4.7 KiB
C
/*
|
|
|
|
u8g_delay.c
|
|
|
|
Universal 8bit Graphics Library
|
|
|
|
Copyright (c) 2011, olikraus@gmail.com
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
are permitted provided that the following conditions are met:
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list
|
|
of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
list of conditions and the following disclaimer in the documentation and/or other
|
|
materials provided with the distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
*/
|
|
|
|
|
|
#include "u8g.h"
|
|
|
|
/*==== Part 1: Derive suitable delay procedure ====*/
|
|
|
|
#if defined(ARDUINO)
|
|
# if defined(__AVR__)
|
|
# define USE_AVR_DELAY
|
|
# elif defined(__PIC32MX)
|
|
# define USE_PIC32_DELAY
|
|
# elif defined(__arm__) /* Arduino Due */
|
|
# define USE_ARDUINO_DELAY
|
|
# else
|
|
# define USE_ARDUINO_DELAY
|
|
# endif
|
|
#elif defined(__AVR__)
|
|
# define USE_AVR_DELAY
|
|
#elif defined(__18CXX)
|
|
# define USE_PIC18_DELAY
|
|
#else
|
|
# define USE_DUMMY_DELAY
|
|
#endif
|
|
|
|
|
|
|
|
/*==== Part 2: Definition of the delay procedures ====*/
|
|
|
|
/*== AVR Delay ==*/
|
|
|
|
#if defined(USE_AVR_DELAY)
|
|
#include <avr/interrupt.h>
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
|
|
/*
|
|
Delay by the provided number of milliseconds.
|
|
Thus, a 16 bit value will allow a delay of 0..65 seconds
|
|
Makes use of the _delay_loop_2
|
|
|
|
_delay_loop_2 will do a delay of n * 4 prozessor cycles.
|
|
with f = F_CPU cycles per second,
|
|
n = f / (1000 * 4 )
|
|
with f = 16000000 the result is 4000
|
|
with f = 1000000 the result is 250
|
|
|
|
the millisec loop, gcc requires the following overhead:
|
|
- movev 1
|
|
- subwi 2x2
|
|
- bne i 2
|
|
==> 7 cycles
|
|
==> must be devided by 4, rounded up 7/4 = 2
|
|
*/
|
|
void u8g_Delay(uint16_t val)
|
|
{
|
|
/* old version did a call to the arduino lib: delay(val); */
|
|
while( val != 0 )
|
|
{
|
|
_delay_loop_2( (F_CPU / 4000 ) -2);
|
|
val--;
|
|
}
|
|
}
|
|
|
|
/* delay by one micro second */
|
|
void u8g_MicroDelay(void)
|
|
{
|
|
#if (F_CPU / 4000000 ) > 0
|
|
_delay_loop_2( (F_CPU / 4000000 ) );
|
|
#endif
|
|
}
|
|
|
|
/* delay by 10 micro seconds */
|
|
void u8g_10MicroDelay(void)
|
|
{
|
|
#if (F_CPU / 400000 ) > 0
|
|
_delay_loop_2( (F_CPU / 400000 ) );
|
|
#endif
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
/*== Delay for PIC18 (not tested) ==*/
|
|
|
|
#if defined(USE_PIC18_DELAY)
|
|
#include <delays.h>
|
|
#define GetSystemClock() (64000000ul) // Hz
|
|
#define GetInstructionClock() (GetSystemClock()/4)
|
|
|
|
void u8g_Delay(uint16_t val)
|
|
{/*
|
|
unsigned int _iTemp = (val);
|
|
while(_iTemp--)
|
|
Delay1KTCYx((GetInstructionClock()+999999)/1000000);
|
|
*/
|
|
}
|
|
void u8g_MicroDelay(void)
|
|
{
|
|
/* not implemented */
|
|
}
|
|
void u8g_10MicroDelay(void)
|
|
{
|
|
/* not implemented */
|
|
}
|
|
#endif
|
|
|
|
|
|
/*== Arduino Delay ==*/
|
|
#if defined(USE_ARDUINO_DELAY)
|
|
void u8g_Delay(uint16_t val)
|
|
{
|
|
delay(val);
|
|
}
|
|
void u8g_MicroDelay(void)
|
|
{
|
|
delayMicroseconds(1);
|
|
}
|
|
void u8g_10MicroDelay(void)
|
|
{
|
|
delayMicroseconds(10);
|
|
}
|
|
#endif
|
|
|
|
#if defined(USE_PIC32_DELAY)
|
|
/*
|
|
Assume chipkit here with F_CPU correctly defined
|
|
The problem was, that u8g_Delay() is called within the constructor.
|
|
It seems that the chipkit is not fully setup at this time, so a
|
|
call to delay() will not work. So here is my own implementation.
|
|
|
|
*/
|
|
#define CPU_COUNTS_PER_SECOND (F_CPU/2UL)
|
|
#define TICKS_PER_MILLISECOND (CPU_COUNTS_PER_SECOND/1000UL)
|
|
#include "plib.h"
|
|
void u8g_Delay(uint16_t val)
|
|
{
|
|
uint32_t d;
|
|
uint32_t s;
|
|
d = val;
|
|
d *= TICKS_PER_MILLISECOND;
|
|
s = ReadCoreTimer();
|
|
while ( (uint32_t)(ReadCoreTimer() - s) < d )
|
|
;
|
|
}
|
|
|
|
void u8g_MicroDelay(void)
|
|
{
|
|
uint32_t d;
|
|
uint32_t s;
|
|
d = TICKS_PER_MILLISECOND/1000;
|
|
s = ReadCoreTimer();
|
|
while ( (uint32_t)(ReadCoreTimer() - s) < d )
|
|
;
|
|
}
|
|
|
|
void u8g_10MicroDelay(void)
|
|
{
|
|
uint32_t d;
|
|
uint32_t s;
|
|
d = TICKS_PER_MILLISECOND/100;
|
|
s = ReadCoreTimer();
|
|
while ( (uint32_t)(ReadCoreTimer() - s) < d )
|
|
;
|
|
}
|
|
|
|
#endif
|
|
|
|
/*== Any other systems: Dummy Delay ==*/
|
|
#if defined(USE_DUMMY_DELAY)
|
|
void u8g_Delay(uint16_t val)
|
|
{
|
|
/* do not know how to delay... */
|
|
}
|
|
void u8g_MicroDelay(void)
|
|
{
|
|
}
|
|
void u8g_10MicroDelay(void)
|
|
{
|
|
}
|
|
#endif
|