Update the delay functions and change the default pinmap for character displays (#7434)

This commit is contained in:
Chris Pepper 2017-08-05 01:20:01 +01:00 committed by Scott Lahteine
parent 105324b85b
commit 9a950e3a5a
2 changed files with 22 additions and 9 deletions

View file

@ -275,11 +275,11 @@
#define LCD_PINS_ENABLE 51 // (MOSI) J3-10 & AUX-3
#define LCD_PINS_D4 52 // (SCK) J3-9 & AUX-3
#define LCD_PINS_D5 59 // J3-8 & AUX-2
#define LCD_PINS_D5 71 // ENET_MDIO
#define DOGLCD_A0 59 // J3-8 & AUX-2
#define LCD_PINS_D6 63 // J5-3 & AUX-2
#define LCD_PINS_D6 73 // ENET_RX_ER
#define DOGLCD_CS 63 // J5-3 & AUX-2
#define LCD_PINS_D7 6 // (SERVO1) J5-1 & SERVO connector
#define LCD_PINS_D7 75 // ENET_RXD1
//#define MISO 50 // system defined J3-10 & AUX-3

View file

@ -43,17 +43,28 @@ uint32_t millis() {
return _millis;
}
//todo: recheck all of this
void delayMicroseconds(uint32_t us) {
if (us < 2) return; // function jump, compare, return about 1us
us--;
static const int nop_factor = (SystemCoreClock / 10000000); // measured accurate at 10us
static const int nop_factor = (SystemCoreClock / 11000000);
static volatile int loops = 0;
if (us < 20) { // burn cycles
//previous ops already burned most of 1us, burn the rest
loops = nop_factor / 4; //measured at 1us
while (loops > 0) --loops;
if (us < 2) return;
us--;
//redirect to delay for large values, then set new delay to remainder
if (us > 1000) {
delay(us / 1000);
us = us % 1000;
}
if (us < 5) { // burn cycles, time in interrupts will not be taken into account
loops = us * nop_factor;
while (loops > 0) --loops;
}
else { // poll systick
else { // poll systick, more accurate through interrupts
int32_t start = SysTick->VAL;
int32_t load = SysTick->LOAD;
int32_t end = start - (load / 1000) * us;
@ -67,6 +78,8 @@ void delayMicroseconds(uint32_t us) {
extern "C" void delay(int msec) {
volatile int32_t end = _millis + msec;
SysTick->VAL = SysTick->LOAD; // reset systick counter so next systick is in exactly 1ms
// this could extend the time between systicks by upto 1ms
while (_millis < end) __WFE();
}