Better handling of DELAY_NS and DELAY_US (#10716)
Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
@ -21,12 +21,13 @@
|
||||
#ifdef TARGET_LPC1768
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../Delay.h"
|
||||
|
||||
HalSerial usb_serial;
|
||||
|
||||
// U8glib required functions
|
||||
extern "C" void u8g_xMicroDelay(uint16_t val) {
|
||||
delayMicroseconds(val);
|
||||
DELAY_US(val);
|
||||
}
|
||||
extern "C" void u8g_MicroDelay(void) {
|
||||
u8g_xMicroDelay(1);
|
||||
|
@ -68,9 +68,9 @@ extern "C" volatile uint32_t _millis;
|
||||
#include "HAL_timers.h"
|
||||
#include "HardwareSerial.h"
|
||||
|
||||
#define ST7920_DELAY_1 DELAY_20_NOP;DELAY_20_NOP;DELAY_20_NOP
|
||||
#define ST7920_DELAY_2 DELAY_20_NOP;DELAY_20_NOP;DELAY_20_NOP;DELAY_10_NOP;DELAY_5_NOP
|
||||
#define ST7920_DELAY_3 DELAY_20_NOP;DELAY_20_NOP;DELAY_20_NOP;DELAY_10_NOP;DELAY_5_NOP
|
||||
#define ST7920_DELAY_1 DELAY_NS(600)
|
||||
#define ST7920_DELAY_2 DELAY_NS(750)
|
||||
#define ST7920_DELAY_3 DELAY_NS(750)
|
||||
|
||||
extern HalSerial usb_serial;
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
//
|
||||
//#include <WInterrupts.h>
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../Delay.h"
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <Arduino.h>
|
||||
@ -78,28 +79,9 @@ static const DELAY_TABLE table[] = {
|
||||
// Private methods
|
||||
//
|
||||
|
||||
#if 0
|
||||
/* static */
|
||||
inline void SoftwareSerial::tunedDelay(const uint32_t count) {
|
||||
|
||||
asm volatile(
|
||||
|
||||
"mov r3, %[loopsPerMicrosecond] \n\t" //load the initial loop counter
|
||||
"1: \n\t"
|
||||
"sub r3, r3, #1 \n\t"
|
||||
"bne 1b \n\t"
|
||||
|
||||
://empty output list
|
||||
:[loopsPerMicrosecond] "r" (count)
|
||||
:"r3", "cc" //clobber list
|
||||
);
|
||||
|
||||
DELAY_US(count);
|
||||
}
|
||||
#else
|
||||
inline void SoftwareSerial::tunedDelay(const uint32_t count) {
|
||||
delayMicroseconds(count);
|
||||
}
|
||||
#endif
|
||||
|
||||
// This function sets the current object as the "listening"
|
||||
// one and returns true if it replaces another
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <lpc17xx_pinsel.h>
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../Delay.h"
|
||||
|
||||
// Interrupts
|
||||
void cli(void) { __disable_irq(); } // Disable
|
||||
@ -40,26 +41,9 @@ uint32_t millis() {
|
||||
return _millis;
|
||||
}
|
||||
|
||||
// This is required for some Arduino libraries we are using
|
||||
void delayMicroseconds(uint32_t us) {
|
||||
static const int nop_factor = (SystemCoreClock / 11000000);
|
||||
static volatile int loops = 0;
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
// burn cycles, time in interrupts will not be taken into account
|
||||
loops = us * nop_factor;
|
||||
while (loops > 0) --loops;
|
||||
DELAY_US(us);
|
||||
}
|
||||
|
||||
extern "C" void delay(const int msec) {
|
||||
|
@ -63,7 +63,6 @@
|
||||
|
||||
#include <U8glib.h>
|
||||
|
||||
void delayMicroseconds(uint32_t us);
|
||||
//void pinMode(int16_t pin, uint8_t mode);
|
||||
//void digitalWrite(int16_t pin, uint8_t pin_status);
|
||||
|
||||
@ -122,13 +121,13 @@ uint8_t u8g_i2c_start_sw(uint8_t sla) { // assert start condition and then send
|
||||
|
||||
LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
||||
LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
||||
delayMicroseconds(2);
|
||||
DELAY_US(2);
|
||||
LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
||||
delayMicroseconds(2);
|
||||
DELAY_US(2);
|
||||
LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOSET = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
||||
delayMicroseconds(2);
|
||||
DELAY_US(2);
|
||||
LPC_GPIO(SDA_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SDA_pin_HAL_LPC1768_sw_I2C);
|
||||
delayMicroseconds(2);
|
||||
DELAY_US(2);
|
||||
LPC_GPIO(SCL_port_HAL_LPC1768_sw_I2C)->FIOCLR = LPC_PIN(SCL_pin_HAL_LPC1768_sw_I2C);
|
||||
|
||||
u8g_i2c_send_byte_sw(I2C_SLA); // send slave address with write bit
|
||||
|
Reference in New Issue
Block a user