Commit 1f7a20c1 authored by Eric Duminil's avatar Eric Duminil
Browse files

Merge branch 'develop'

parents da1f41c0 34496cfe
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
#include <Arduino.h> #include <Arduino.h>
#include "driver/rmt.h" #include "driver/rmt.h"
#if defined(ESP_IDF_VERSION)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
#define HAS_ESP_IDF_4
#endif
#endif
// This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered // This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered
// to work with the Arduino version of the ESP-IDF (3.2) // to work with the Arduino version of the ESP-IDF (3.2)
...@@ -89,6 +95,7 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) ...@@ -89,6 +95,7 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
if (!rmt_reserved_channels[i]) { if (!rmt_reserved_channels[i]) {
rmt_reserved_channels[i] = true; rmt_reserved_channels[i] = true;
channel = i; channel = i;
break;
} }
} }
if (channel == ADAFRUIT_RMT_CHANNEL_MAX) { if (channel == ADAFRUIT_RMT_CHANNEL_MAX) {
...@@ -96,6 +103,10 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) ...@@ -96,6 +103,10 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
return; return;
} }
#if defined(HAS_ESP_IDF_4)
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin, channel);
config.clk_div = 2;
#else
// Match default TX config from ESP-IDF version 3.4 // Match default TX config from ESP-IDF version 3.4
rmt_config_t config = { rmt_config_t config = {
.rmt_mode = RMT_MODE_TX, .rmt_mode = RMT_MODE_TX,
...@@ -113,12 +124,16 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) ...@@ -113,12 +124,16 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
.idle_output_en = true, .idle_output_en = true,
} }
}; };
#endif
rmt_config(&config); rmt_config(&config);
rmt_driver_install(config.channel, 0, 0); rmt_driver_install(config.channel, 0, 0);
// Convert NS timings to ticks // Convert NS timings to ticks
uint32_t counter_clk_hz = 0; uint32_t counter_clk_hz = 0;
#if defined(HAS_ESP_IDF_4)
rmt_get_counter_clock(channel, &counter_clk_hz);
#else
// this emulates the rmt_get_counter_clock() function from ESP-IDF 3.4 // this emulates the rmt_get_counter_clock() function from ESP-IDF 3.4
if (RMT_LL_HW_BASE->conf_ch[config.channel].conf1.ref_always_on == RMT_BASECLK_REF) { if (RMT_LL_HW_BASE->conf_ch[config.channel].conf1.ref_always_on == RMT_BASECLK_REF) {
uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt; uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt;
...@@ -129,6 +144,7 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) ...@@ -129,6 +144,7 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
uint32_t div = div_cnt == 0 ? 256 : div_cnt; uint32_t div = div_cnt == 0 ? 256 : div_cnt;
counter_clk_hz = APB_CLK_FREQ / (div); counter_clk_hz = APB_CLK_FREQ / (div);
} }
#endif
// NS to tick converter // NS to tick converter
float ratio = (float)counter_clk_hz / 1e9; float ratio = (float)counter_clk_hz / 1e9;
......
...@@ -17,16 +17,16 @@ static inline uint32_t _getCycleCount(void) { ...@@ -17,16 +17,16 @@ static inline uint32_t _getCycleCount(void) {
} }
#ifdef ESP8266 #ifdef ESP8266
void ICACHE_RAM_ATTR espShow( IRAM_ATTR void espShow(
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { uint8_t pin, uint8_t *pixels, uint32_t numBytes, __attribute__((unused)) boolean is800KHz) {
#else #else
void espShow( void espShow(
uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
#endif #endif
#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us #define CYCLES_800_T0H (F_CPU / 2500001) // 0.4us
#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us #define CYCLES_800_T1H (F_CPU / 1250001) // 0.8us
#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit #define CYCLES_800 (F_CPU / 800001) // 1.25us per bit
#define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS #define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS
#define CYCLES_400_T1H (F_CPU / 833333) // 1.2us #define CYCLES_400_T1H (F_CPU / 833333) // 1.2us
#define CYCLES_400 (F_CPU / 400000) // 2.5us per bit #define CYCLES_400 (F_CPU / 400000) // 2.5us per bit
......
name=Adafruit NeoPixel name=Adafruit NeoPixel
version=1.7.0 version=1.10.4
author=Adafruit author=Adafruit
maintainer=Adafruit <info@adafruit.com> maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for controlling single-wire-based LED pixels and strip. sentence=Arduino library for controlling single-wire-based LED pixels and strip.
......
// -------------------------------------------------- //
// This file is autogenerated by pioasm; do not edit! //
// -------------------------------------------------- //
// Unless you know what you are doing...
// Lines 47 and 52 have been edited to set transmit bit count
#if !PICO_NO_HARDWARE
#include "hardware/pio.h"
#endif
// ------ //
// ws2812 //
// ------ //
#define ws2812_wrap_target 0
#define ws2812_wrap 3
#define ws2812_T1 2
#define ws2812_T2 5
#define ws2812_T3 3
static const uint16_t ws2812_program_instructions[] = {
// .wrap_target
0x6221, // 0: out x, 1 side 0 [2]
0x1123, // 1: jmp !x, 3 side 1 [1]
0x1400, // 2: jmp 0 side 1 [4]
0xa442, // 3: nop side 0 [4]
// .wrap
};
#if !PICO_NO_HARDWARE
static const struct pio_program ws2812_program = {
.instructions = ws2812_program_instructions,
.length = 4,
.origin = -1,
};
static inline pio_sm_config ws2812_program_get_default_config(uint offset) {
pio_sm_config c = pio_get_default_sm_config();
sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap);
sm_config_set_sideset(&c, 1, false, false);
return c;
}
#include "hardware/clocks.h"
static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin,
float freq, uint bits) {
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
pio_sm_config c = ws2812_program_get_default_config(offset);
sm_config_set_sideset_pins(&c, pin);
sm_config_set_out_shift(&c, false, true,
bits); // <----<<< Length changed to "bits"
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3;
float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit);
sm_config_set_clkdiv(&c, div);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
#endif
language: c
sudo: false
before_install:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
script:
- build_platform esp8266
notifications:
email:
on_success: change
on_failure: change
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#define SEVENZYYEARS 2208988800UL #define SEVENZYYEARS 2208988800UL
#define NTP_PACKET_SIZE 48 #define NTP_PACKET_SIZE 48
#define NTP_DEFAULT_LOCAL_PORT 1337 #define NTP_DEFAULT_LOCAL_PORT 1337
#define LEAP_YEAR(Y) ( (Y>0) && !(Y%4) && ( (Y%100) || !(Y%400) ) )
class NTPClient { class NTPClient {
private: private:
...@@ -16,8 +14,9 @@ class NTPClient { ...@@ -16,8 +14,9 @@ class NTPClient {
bool _udpSetup = false; bool _udpSetup = false;
const char* _poolServerName = "pool.ntp.org"; // Default time server const char* _poolServerName = "pool.ntp.org"; // Default time server
int _port = NTP_DEFAULT_LOCAL_PORT; IPAddress _poolServerIP;
int _timeOffset = 0; unsigned int _port = NTP_DEFAULT_LOCAL_PORT;
long _timeOffset = 0;
unsigned long _updateInterval = 60000; // In ms unsigned long _updateInterval = 60000; // In ms
...@@ -27,14 +26,28 @@ class NTPClient { ...@@ -27,14 +26,28 @@ class NTPClient {
byte _packetBuffer[NTP_PACKET_SIZE]; byte _packetBuffer[NTP_PACKET_SIZE];
void sendNTPPacket(); void sendNTPPacket();
bool isValid(byte * ntpPacket);
public: public:
NTPClient(UDP& udp); NTPClient(UDP& udp);
NTPClient(UDP& udp, int timeOffset); NTPClient(UDP& udp, long timeOffset);
NTPClient(UDP& udp, const char* poolServerName); NTPClient(UDP& udp, const char* poolServerName);
NTPClient(UDP& udp, const char* poolServerName, int timeOffset); NTPClient(UDP& udp, const char* poolServerName, long timeOffset);
NTPClient(UDP& udp, const char* poolServerName, int timeOffset, unsigned long updateInterval); NTPClient(UDP& udp, const char* poolServerName, long timeOffset, unsigned long updateInterval);
NTPClient(UDP& udp, IPAddress poolServerIP);
NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset);
NTPClient(UDP& udp, IPAddress poolServerIP, long timeOffset, unsigned long updateInterval);
/**
* Set time server name
*
* @param poolServerName
*/
void setPoolServerName(const char* poolServerName);
/**
* Set random local port
*/
void setRandomPort(unsigned int minValue = 49152, unsigned int maxValue = 65535);
/** /**
* Starts the underlying UDP client with the default local port * Starts the underlying UDP client with the default local port
...@@ -44,7 +57,7 @@ class NTPClient { ...@@ -44,7 +57,7 @@ class NTPClient {
/** /**
* Starts the underlying UDP client with the specified local port * Starts the underlying UDP client with the specified local port
*/ */
void begin(int port); void begin(unsigned int port);
/** /**
* This should be called in the main loop of your application. By default an update from the NTP Server is only * This should be called in the main loop of your application. By default an update from the NTP Server is only
...@@ -61,10 +74,17 @@ class NTPClient { ...@@ -61,10 +74,17 @@ class NTPClient {
*/ */
bool forceUpdate(); bool forceUpdate();
int getDay(); /**
int getHours(); * This allows to check if the NTPClient successfully received a NTP packet and set the time.
int getMinutes(); *
int getSeconds(); * @return true if time has been set, else false
*/
bool isTimeSet() const;
int getDay() const;
int getHours() const;
int getMinutes() const;
int getSeconds() const;
/** /**
* Changes the time offset. Useful for changing timezones dynamically * Changes the time offset. Useful for changing timezones dynamically
...@@ -78,28 +98,37 @@ class NTPClient { ...@@ -78,28 +98,37 @@ class NTPClient {
void setUpdateInterval(unsigned long updateInterval); void setUpdateInterval(unsigned long updateInterval);
/** /**
* @return secs argument (or 0 for current time) formatted like `hh:mm:ss` * @return time formatted like `hh:mm:ss`
*/ */
void getFormattedTime(char *formatted_time, unsigned long secs = 0); String getFormattedTime() const;
/** /**
* @return time in seconds since Jan. 1, 1970 * @return time in seconds since Jan. 1, 1970
*/ */
unsigned long getEpochTime(); unsigned long getEpochTime() const;
/** /**
* @return secs argument (or 0 for current date) formatted to ISO 8601 * Stops the underlying UDP client
* like `2004-02-12T15:19:21+00:00`
*/ */
void getFormattedDate(char *formatted_date, unsigned long secs = 0); void end();
/*** Custom code for ampel-firmware ***/
/** /**
* Stops the underlying UDP client * @return secs argument (or 0 for current time) formatted like `hh:mm:ss`
*/ */
void end(); void getFormattedTime(char *formatted_time, unsigned long secs = 0);
/**
* @return secs argument (or 0 for current date) formatted to ISO 8601
* like `2004-02-12T15:19:21+00:00`
*/
void getFormattedDate(char *formatted_date, unsigned long secs = 0);
/** /**
* Replace the NTP-fetched time with seconds since Jan. 1, 1970 * Replace the NTP-fetched time with seconds since Jan. 1, 1970
*/ */
void setEpochTime(unsigned long secs); void setEpochTime(unsigned long secs);
/**************************************************************/
}; };
# NTPClient # NTPClient
[![Build Status](https://travis-ci.org/arduino-libraries/NTPClient.svg?branch=master)](https://travis-ci.org/arduino-libraries/NTPClient) [![Check Arduino status](https://github.com/arduino-libraries/NTPClient/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/check-arduino.yml)
[![Compile Examples status](https://github.com/arduino-libraries/NTPClient/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/compile-examples.yml)
[![Spell Check status](https://github.com/arduino-libraries/NTPClient/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/spell-check.yml)
Connect to a NTP server, here is how: Connect to a NTP server, here is how:
...@@ -22,7 +24,7 @@ WiFiUDP ntpUDP; ...@@ -22,7 +24,7 @@ WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP); NTPClient timeClient(ntpUDP);
// You can specify the time server pool and the offset, (in seconds) // You can specify the time server pool and the offset, (in seconds)
// additionaly you can specify the update interval (in milliseconds). // additionally you can specify the update interval (in milliseconds).
// NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); // NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
void setup(){ void setup(){
...@@ -45,3 +47,6 @@ void loop() { ...@@ -45,3 +47,6 @@ void loop() {
delay(1000); delay(1000);
} }
``` ```
## Function documentation
`getEpochTime` returns the Unix epoch, which are the seconds elapsed since 00:00:00 UTC on 1 January 1970 (leap seconds are ignored, every day is treated as having 86400 seconds). **Attention**: If you have set a time offset this time offset will be added to your epoch timestamp.
...@@ -12,9 +12,13 @@ begin KEYWORD2 ...@@ -12,9 +12,13 @@ begin KEYWORD2
end KEYWORD2 end KEYWORD2
update KEYWORD2 update KEYWORD2
forceUpdate KEYWORD2 forceUpdate KEYWORD2
isTimeSet KEYWORD2
getDay KEYWORD2 getDay KEYWORD2
getHours KEYWORD2 getHours KEYWORD2
getMinutes KEYWORD2 getMinutes KEYWORD2
getSeconds KEYWORD2 getSeconds KEYWORD2
getFormattedTime KEYWORD2 getFormattedTime KEYWORD2
getEpochTime KEYWORD2 getEpochTime KEYWORD2
setTimeOffset KEYWORD2
setUpdateInterval KEYWORD2
setPoolServerName KEYWORD2
name=NTPClient name=NTPClient
version=3.1.0 version=3.2.0
author=Fabrice Weinberg author=Fabrice Weinberg
maintainer=Fabrice Weinberg <fabrice@weinberg.me> maintainer=Fabrice Weinberg <fabrice@weinberg.me>
sentence=An NTPClient to connect to a time server sentence=An NTPClient to connect to a time server
......
name=SparkFun SCD30 Arduino Library name=SparkFun SCD30 Arduino Library
version=1.0.13 version=1.0.17
author=SparkFun Electronics author=SparkFun Electronics
maintainer=SparkFun Electronics <sparkfun.com> maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the Sensirion SCD30 CO2 Sensor sentence=Library for the Sensirion SCD30 CO2 Sensor
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment