Merge branch 'master' into feature/travis-test

This commit is contained in:
sheinz 2016-11-12 01:36:37 +02:00
commit f7bba2b386
91 changed files with 1491 additions and 239 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ firmware
local.mk
local.h
screenlog.*
*.swp

View file

@ -44,7 +44,7 @@
#define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 )
#endif
#ifndef configTICK_RATE_HZ
#define configTICK_RATE_HZ ( ( portTickType ) 100 )
#define configTICK_RATE_HZ ( ( TickType_t ) 100 )
#endif
#ifndef configMAX_PRIORITIES
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 15 )
@ -140,5 +140,9 @@ to exclude the API function. */
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#endif
#ifndef configENABLE_BACKWARD_COMPATIBILITY
#define configENABLE_BACKWARD_COMPATIBILITY 0
#endif
#endif /* __DEFAULT_FREERTOS_CONFIG_H */

View file

@ -94,7 +94,7 @@ void *xPortSupervisorStackPointer;
/*
* Stack initialization
*/
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
{
#define SET_STKREG(r,v) sp[(r) >> 2] = (portSTACK_TYPE)(v)
portSTACK_TYPE *sp, *tp;
@ -259,7 +259,7 @@ void IRAM vPortExitCritical( void )
}
/* Backward compatibility with libmain.a and libpp.a and can remove when these are open. */
signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions )
signed portBASE_TYPE xTaskGenericCreate( TaskFunction_t pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, TaskHandle_t *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const MemoryRegion_t * const xRegions )
{
(void)puxStackBuffer; (void)xRegions;
return xTaskCreate( pxTaskCode, (const char * const)pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask);

View file

@ -100,13 +100,12 @@ typedef portSTACK_TYPE StackType_t;
typedef portBASE_TYPE BaseType_t;
typedef unsigned portBASE_TYPE UBaseType_t;
typedef uint32_t portTickType;
typedef uint32_t TickType_t;
#define portMAX_DELAY ( portTickType ) 0xffffffff
#define portMAX_DELAY ( TickType_t ) 0xffffffff
/* Architecture specifics. */
#define portSTACK_GROWTH ( -1 )
#define portTICK_PERIOD_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
#define portBYTE_ALIGNMENT 8
/*-----------------------------------------------------------*/

View file

@ -138,7 +138,7 @@ $(1)_AR_IN_FILES = $$($(1)_OBJ_FILES)
# the component is shown to depend on both obj and source files so we get
# a meaningful error message for missing explicitly named source files
ifeq ($(INCLUDE_SRC_INTO_AR),1)
ifeq ($(INCLUDE_SRC_IN_AR),1)
$(1)_SRC_IN_AR_FILES = $$($(1)_SRC_FILES)
endif

View file

@ -52,10 +52,10 @@ uint8_t sdk_user_init_flag;
struct sdk_info_st sdk_info;
// xUserTaskHandle -- .bss+0x28
xTaskHandle sdk_xUserTaskHandle;
TaskHandle_t sdk_xUserTaskHandle;
// xWatchDogTaskHandle -- .bss+0x2c
xTaskHandle sdk_xWatchDogTaskHandle;
TaskHandle_t sdk_xWatchDogTaskHandle;
/* Static function prototypes */
@ -227,7 +227,7 @@ void IRAM sdk_user_start(void) {
}
// .text+0x3a8
void IRAM vApplicationStackOverflowHook(xTaskHandle task, char *task_name) {
void IRAM vApplicationStackOverflowHook(TaskHandle_t task, char *task_name) {
printf("Task stack overflow (high water mark=%lu name=\"%s\")\n", uxTaskGetStackHighWaterMark(task), task_name);
}

View file

@ -59,14 +59,9 @@ __attribute__((weak)) long _write_r(struct _reent *r, int fd, const char *ptr, i
}
/* syscall implementation for stdio read from UART */
__attribute__((weak)) long _read_r( struct _reent *r, int fd, char *ptr, int len )
__attribute__((weak)) long _read_stdin_r(struct _reent *r, int fd, char *ptr, int len)
{
int ch, i;
if(fd != r->_stdin->_file) {
r->_errno = EBADF;
return -1;
}
uart_rxfifo_wait(0, 1);
for(i = 0; i < len; i++) {
ch = uart_getc_nowait(0);
@ -76,6 +71,15 @@ __attribute__((weak)) long _read_r( struct _reent *r, int fd, char *ptr, int len
return i;
}
__attribute__((weak)) long _read_r( struct _reent *r, int fd, char *ptr, int len )
{
if(fd != r->_stdin->_file) {
r->_errno = EBADF;
return -1;
}
return _read_stdin_r(r, fd, ptr, len);
}
/* Stub syscall implementations follow, to allow compiling newlib functions that
pull these in via various codepaths
*/

View file

@ -114,7 +114,7 @@ static struct {
uint32_t end_addr;
size_t region_size;
bool force_compact;
xSemaphoreHandle sem;
SemaphoreHandle_t sem;
} _sysparam_info;
/***************************** Internal routines *****************************/

View file

@ -84,7 +84,7 @@ static void telnetTask(void *pvParameters)
char buf[80];
snprintf(buf, sizeof(buf), "Uptime %d seconds\r\n",
xTaskGetTickCount()*portTICK_RATE_MS/1000);
xTaskGetTickCount()*portTICK_PERIOD_MS/1000);
netconn_write(client, buf, strlen(buf), NETCONN_COPY);
snprintf(buf, sizeof(buf), "Free heap %d bytes\r\n", (int)xPortGetFreeHeapSize());
netconn_write(client, buf, strlen(buf), NETCONN_COPY);

View file

@ -31,7 +31,7 @@ extern char *ca_cert, *client_endpoint, *client_cert, *client_key;
static int wifi_alive = 0;
static int ssl_reset;
static SSLConnection *ssl_conn;
static xQueueHandle publish_queue;
static QueueHandle_t publish_queue;
static void beat_task(void *pvParameters) {
char msg[16];
@ -39,7 +39,7 @@ static void beat_task(void *pvParameters) {
while (1) {
if (!wifi_alive) {
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
continue;
}
@ -50,7 +50,7 @@ static void beat_task(void *pvParameters) {
printf("Publish queue overflow\r\n");
}
vTaskDelay(10000 / portTICK_RATE_MS);
vTaskDelay(10000 / portTICK_PERIOD_MS);
}
}
@ -142,7 +142,7 @@ static void mqtt_task(void *pvParameters) {
ssl_conn = (SSLConnection *) malloc(sizeof(SSLConnection));
while (1) {
if (!wifi_alive) {
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
continue;
}
@ -191,7 +191,7 @@ static void mqtt_task(void *pvParameters) {
while (wifi_alive && !ssl_reset) {
char msg[64];
while (xQueueReceive(publish_queue, (void *) msg, 0) == pdTRUE) {
portTickType task_tick = xTaskGetTickCount();
TickType_t task_tick = xTaskGetTickCount();
uint32_t free_heap = xPortGetFreeHeapSize();
uint32_t free_stack = uxTaskGetStackHighWaterMark(NULL);
snprintf(msg, sizeof(msg), "%u: free heap %u, free stack %u",
@ -246,7 +246,7 @@ static void wifi_task(void *pvParameters) {
printf("WiFi: connection failed\r\n");
break;
}
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
--retries;
}
@ -256,12 +256,12 @@ static void wifi_task(void *pvParameters) {
printf("WiFi: Connected\n\r");
wifi_alive = 1;
}
vTaskDelay(500 / portTICK_RATE_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
wifi_alive = 0;
printf("WiFi: disconnected\n\r");
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

View file

@ -133,7 +133,7 @@ int ssl_connect(SSLConnection* conn, const char* host, int port) {
}
handle_error(ret);
vTaskDelay(5000 / portTICK_RATE_MS);
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
mbedtls_ssl_get_record_expansion(&conn->ssl_ctx);

View file

@ -19,9 +19,9 @@ void blinkenTask(void *pvParameters)
gpio_enable(gpio, GPIO_OUTPUT);
while(1) {
gpio_write(gpio, 1);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_write(gpio, 0);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
@ -45,9 +45,9 @@ void blinkenRegisterTask(void *pvParameters)
IOMUX_GPIO2 = IOMUX_GPIO2_FUNC_GPIO | IOMUX_PIN_OUTPUT_ENABLE; /* change this line if you change 'gpio' */
while(1) {
GPIO.OUT_SET = BIT(gpio);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
GPIO.OUT_CLEAR = BIT(gpio);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

View file

@ -26,11 +26,11 @@ typedef struct
} my_event_t;
// Communication Queue
static xQueueHandle mainqueue;
static xTimerHandle timerHandle;
static QueueHandle_t mainqueue;
static TimerHandle_t timerHandle;
// Own BMP180 User Inform Implementation
bool bmp180_i2c_informUser(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure)
bool bmp180_i2c_informUser(const QueueHandle_t* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure)
{
my_event_t ev;
@ -43,7 +43,7 @@ bool bmp180_i2c_informUser(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_
}
// Timer call back
static void bmp180_i2c_timer_cb(xTimerHandle xTimer)
static void bmp180_i2c_timer_cb(TimerHandle_t xTimer)
{
my_event_t ev;
ev.event_type = MY_EVT_TIMER;
@ -55,7 +55,7 @@ static void bmp180_i2c_timer_cb(xTimerHandle xTimer)
void bmp180_task(void *pvParameters)
{
// Received pvParameters is communication queue
xQueueHandle *com_queue = (xQueueHandle *)pvParameters;
QueueHandle_t *com_queue = (QueueHandle_t *)pvParameters;
printf("%s: Started user interface task\n", __FUNCTION__);
@ -116,7 +116,7 @@ void user_init(void)
xTaskCreate(bmp180_task, "bmp180_task", 256, &mainqueue, 2, NULL);
// Create Timer (Trigger a measurement every second)
timerHandle = xTimerCreate("BMP180 Trigger", 1000/portTICK_RATE_MS, pdTRUE, NULL, bmp180_i2c_timer_cb);
timerHandle = xTimerCreate("BMP180 Trigger", 1000/portTICK_PERIOD_MS, pdTRUE, NULL, bmp180_i2c_timer_cb);
if (timerHandle != NULL)
{

View file

@ -31,14 +31,14 @@ static void bmp280_task_forced(void *pvParameters)
while (1) {
while (!bmp280_init(&bmp280_dev, &params)) {
printf("BMP280 initialization failed\n");
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
bool bme280p = bmp280_dev.id == BME280_CHIP_ID;
printf("BMP280: found %s\n", bme280p ? "BME280" : "BMP280");
while(1) {
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
if (!bmp280_force_measurement(&bmp280_dev)) {
printf("Failed initiating measurement\n");
break;
@ -72,14 +72,14 @@ static void bmp280_task_normal(void *pvParameters)
while (1) {
while (!bmp280_init(&bmp280_dev, &params)) {
printf("BMP280 initialization failed\n");
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
bool bme280p = bmp280_dev.id == BME280_CHIP_ID;
printf("BMP280: found %s\n", bme280p ? "BME280" : "BMP280");
while(1) {
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
if (!bmp280_read_float(&bmp280_dev, &temperature, &pressure, &humidity)) {
printf("Temperature/pressure reading failed\n");
break;

View file

@ -34,8 +34,8 @@ void buttonPollTask(void *pvParameters)
{
taskYIELD();
}
printf("Polled for button press at %dms\r\n", xTaskGetTickCount()*portTICK_RATE_MS);
vTaskDelay(200 / portTICK_RATE_MS);
printf("Polled for button press at %dms\r\n", xTaskGetTickCount()*portTICK_PERIOD_MS);
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}
@ -50,14 +50,14 @@ void buttonPollTask(void *pvParameters)
void buttonIntTask(void *pvParameters)
{
printf("Waiting for button press interrupt on gpio %d...\r\n", gpio);
xQueueHandle *tsqueue = (xQueueHandle *)pvParameters;
QueueHandle_t *tsqueue = (QueueHandle_t *)pvParameters;
gpio_set_interrupt(gpio, int_type);
uint32_t last = 0;
while(1) {
uint32_t button_ts;
xQueueReceive(*tsqueue, &button_ts, portMAX_DELAY);
button_ts *= portTICK_RATE_MS;
button_ts *= portTICK_PERIOD_MS;
if(last < button_ts-200) {
printf("Button interrupt fired at %dms\r\n", button_ts);
last = button_ts;
@ -65,7 +65,7 @@ void buttonIntTask(void *pvParameters)
}
}
static xQueueHandle tsqueue;
static QueueHandle_t tsqueue;
void GPIO_HANDLER(void)
{

View file

@ -1,4 +1,4 @@
PROGRAM=dht_sensor
PROGRAM = dht_sensor
EXTRA_COMPONENTS = extras/dht
include ../../common.mk

View file

@ -8,7 +8,7 @@
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "dht.h"
#include <dht/dht.h>
#include "esp8266.h"
/* An example using the ubiquitous DHT** humidity sensors
@ -16,6 +16,7 @@
* from a sensor attached to GPIO pin 4.
*/
uint8_t const dht_gpio = 4;
const dht_sensor_type_t sensor_type = DHT_TYPE_DHT22;
void dhtMeasurementTask(void *pvParameters)
{
@ -28,7 +29,7 @@ void dhtMeasurementTask(void *pvParameters)
gpio_set_pullup(dht_gpio, false, false);
while(1) {
if (dht_read_data(dht_gpio, &humidity, &temperature)) {
if (dht_read_data(sensor_type, dht_gpio, &humidity, &temperature)) {
printf("Humidity: %d%% Temp: %dC\n",
humidity / 10,
temperature / 10);
@ -37,7 +38,7 @@ void dhtMeasurementTask(void *pvParameters)
}
// Three second delay...
vTaskDelay(3000 / portTICK_RATE_MS);
vTaskDelay(3000 / portTICK_PERIOD_MS);
}
}

View file

@ -0,0 +1,4 @@
PROGRAM = ds1302_test
EXTRA_COMPONENTS = extras/ds1302
#ESPBAUD = 460800
include ../../common.mk

View file

@ -0,0 +1,48 @@
/*
* Example of using DS1302 RTC driver
*
* Part of esp-open-rtos
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>
* Pavel Merzlyakov <merzlyakovpavel@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#include <esp/uart.h>
#include <espressif/esp_common.h>
#include <ds1302/ds1302.h>
#include <stdio.h>
#define CE_PIN 5
#define IO_PIN 4
#define SCLK_PIN 0
void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());
struct tm time = {
.tm_year = 2016,
.tm_mon = 9,
.tm_mday = 31,
.tm_hour = 21,
.tm_min = 54,
.tm_sec = 10
};
ds1302_init(CE_PIN, IO_PIN, SCLK_PIN);
ds1302_set_write_protect(false);
ds1302_set_time(&time);
ds1302_start(true);
while (true)
{
ds1302_get_time(&time);
printf("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon + 1,
time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
for (uint32_t i = 0; i < 1000; i++)
sdk_os_delay_us(500);
}
}

View file

@ -14,32 +14,33 @@
#define SCL_PIN 5
#define SDA_PIN 4
void user_init (void)
void user_init(void)
{
uart_set_baud (0, 115200);
printf ("SDK version:%s\n", sdk_system_get_sdk_version ());
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());
i2c_init (SCL_PIN, SDA_PIN);
ds1307_start (true);
i2c_init(SCL_PIN, SDA_PIN);
ds1307_start(true);
// setup datetime: 2016-10-09 13:50:10
struct tm time = {
.tm_year = 2016,
.tm_mon = 10,
.tm_mon = 9, // 0-based
.tm_mday = 9,
.tm_hour = 13,
.tm_min = 50,
.tm_sec = 10
.tm_min = 50,
.tm_sec = 10
};
ds1307_set_time (&time);
ds1307_set_time(&time);
while (true)
{
ds1307_get_time (&time);
ds1307_get_time(&time);
printf ("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
printf("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon + 1,
time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
for (uint32_t i = 0; i < 1000; i ++)
sdk_os_delay_us (500);
for (uint32_t i = 0; i < 1000; i++)
sdk_os_delay_us(500);
}
}

View file

@ -88,7 +88,7 @@ void broadcast_temperature(void *pvParameters)
}
netbuf_delete(buf); // De-allocate packet buffer
}
vTaskDelay(1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
err = netconn_disconnect(conn);
@ -97,7 +97,7 @@ void broadcast_temperature(void *pvParameters)
err = netconn_delete(conn);
printf("%s : Deleted connection (%s)\n", __FUNCTION__, lwip_strerr(err));
vTaskDelay(1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}

View file

@ -64,7 +64,7 @@ void print_temperature(void *pvParameters) {
// Wait for a little bit between each sample (note that the
// ds18b20_measure_and_read_multi operation already takes at
// least 750ms to run, so this is on top of that delay).
vTaskDelay(LOOP_DELAY_MS / portTICK_RATE_MS);
vTaskDelay(LOOP_DELAY_MS / portTICK_PERIOD_MS);
}
}
}

View file

@ -93,7 +93,7 @@ void timerRegTask(void *pvParameters)
printf("frc2 handler called %d times, last value 0x%08x\r\n", frc2_handler_call_count,
frc2_last_count_val);
vTaskDelay(500 / portTICK_RATE_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}

View file

@ -229,7 +229,7 @@ void user_init(void)
test_isr();
test_sign_extension();
xTaskHandle taskHandle;
TaskHandle_t taskHandle;
xTaskCreate(test_system_interaction, "interactionTask", 256, &taskHandle, 2, NULL);
}
@ -304,7 +304,7 @@ static void test_system_interaction()
*/
}
uint32_t ticks = xTaskGetTickCount() - start;
printf("Timer interaction test PASSED after %dms.\n", ticks*portTICK_RATE_MS);
printf("Timer interaction test PASSED after %dms.\n", ticks*portTICK_PERIOD_MS);
abort();
}

View file

@ -118,7 +118,7 @@ void rewrite_file_task(void *p)
}
while (false);
vTaskDelay(DELAY_MS / portTICK_RATE_MS);
vTaskDelay(DELAY_MS / portTICK_PERIOD_MS);
}
}

View file

@ -43,7 +43,7 @@ void http_get_task(void *pvParameters)
printf("DNS lookup failed err=%d res=%p\r\n", err, res);
if(res)
freeaddrinfo(res);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
failures++;
continue;
}
@ -55,7 +55,7 @@ void http_get_task(void *pvParameters)
if(s < 0) {
printf("... Failed to allocate socket.\r\n");
freeaddrinfo(res);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
failures++;
continue;
}
@ -66,7 +66,7 @@ void http_get_task(void *pvParameters)
close(s);
freeaddrinfo(res);
printf("... socket connect failed.\r\n");
vTaskDelay(4000 / portTICK_RATE_MS);
vTaskDelay(4000 / portTICK_PERIOD_MS);
failures++;
continue;
}
@ -81,7 +81,7 @@ void http_get_task(void *pvParameters)
if (write(s, req, strlen(req)) < 0) {
printf("... socket send failed\r\n");
close(s);
vTaskDelay(4000 / portTICK_RATE_MS);
vTaskDelay(4000 / portTICK_PERIOD_MS);
failures++;
continue;
}
@ -106,7 +106,7 @@ void http_get_task(void *pvParameters)
printf("successes = %d failures = %d\r\n", successes, failures);
for(int countdown = 10; countdown >= 0; countdown--) {
printf("%d... ", countdown);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("\r\nStarting again!\r\n");
}

View file

@ -181,7 +181,7 @@ void http_get_task(void *pvParameters)
err_t dns_err;
ip_addr_t host_ip;
do {
vTaskDelay(500 / portTICK_RATE_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
dns_err = netconn_gethostbyname(WEB_SERVER, &host_ip);
} while(dns_err != ERR_OK);
printf("done.\n");
@ -313,7 +313,7 @@ void http_get_task(void *pvParameters)
printf("\n\nsuccesses = %d failures = %d\n", successes, failures);
for(int countdown = successes ? 10 : 5; countdown >= 0; countdown--) {
printf("%d... ", countdown);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("\nStarting again!\n");
}

View file

@ -57,7 +57,7 @@ static dma_descriptor_t dma_block_list[DMA_QUEUE_SIZE];
static uint8_t dma_buffer[DMA_QUEUE_SIZE][DMA_BUFFER_SIZE];
// Queue of empty DMA blocks
static xQueueHandle dma_queue;
static QueueHandle_t dma_queue;
/**
* Create a circular list of DMA descriptors
@ -183,7 +183,7 @@ void play_task(void *pvParameters)
printf("underrun counter: %d\n", underrun_counter);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
close(fd);

View file

@ -24,18 +24,18 @@
#define MQTT_USER NULL
#define MQTT_PASS NULL
xSemaphoreHandle wifi_alive;
xQueueHandle publish_queue;
SemaphoreHandle_t wifi_alive;
QueueHandle_t publish_queue;
#define PUB_MSG_LEN 16
static void beat_task(void *pvParameters)
{
portTickType xLastWakeTime = xTaskGetTickCount();
TickType_t xLastWakeTime = xTaskGetTickCount();
char msg[PUB_MSG_LEN];
int count = 0;
while (1) {
vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_RATE_MS);
vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_PERIOD_MS);
printf("beat\r\n");
snprintf(msg, PUB_MSG_LEN, "Beat %d\r\n", count++);
if (xQueueSend(publish_queue, (void *)msg, 0) == pdFALSE) {
@ -190,7 +190,7 @@ static void wifi_task(void *pvParameters)
printf("WiFi: connection failed\r\n");
break;
}
vTaskDelay( 1000 / portTICK_RATE_MS );
vTaskDelay( 1000 / portTICK_PERIOD_MS );
--retries;
}
if (status == STATION_GOT_IP) {
@ -205,7 +205,7 @@ static void wifi_task(void *pvParameters)
}
printf("WiFi: disconnected\n\r");
sdk_wifi_station_disconnect();
vTaskDelay( 1000 / portTICK_RATE_MS );
vTaskDelay( 1000 / portTICK_PERIOD_MS );
}
}

View file

@ -109,10 +109,10 @@ void tftp_client_task(void *pvParameters)
*/
while(1) {
tftpclient_download_and_verify_file1(slot, &conf);
vTaskDelay(5000 / portTICK_RATE_MS);
vTaskDelay(5000 / portTICK_PERIOD_MS);
tftpclient_download_file2(slot);
vTaskDelay(5000 / portTICK_RATE_MS);
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}

View file

@ -8,7 +8,7 @@
void task1(void *pvParameters)
{
xQueueHandle *queue = (xQueueHandle *)pvParameters;
QueueHandle_t *queue = (QueueHandle_t *)pvParameters;
printf("Hello from task1!\r\n");
uint32_t count = 0;
while(1) {
@ -21,7 +21,7 @@ void task1(void *pvParameters)
void task2(void *pvParameters)
{
printf("Hello from task 2!\r\n");
xQueueHandle *queue = (xQueueHandle *)pvParameters;
QueueHandle_t *queue = (QueueHandle_t *)pvParameters;
while(1) {
uint32_t count;
if(xQueueReceive(*queue, &count, 1000)) {
@ -32,7 +32,7 @@ void task2(void *pvParameters)
}
}
static xQueueHandle mainqueue;
static QueueHandle_t mainqueue;
void user_init(void)
{

View file

@ -27,7 +27,7 @@
#define SNTP_SERVERS "0.pool.ntp.org", "1.pool.ntp.org", \
"2.pool.ntp.org", "3.pool.ntp.org"
#define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_RATE_MS)
#define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_PERIOD_MS)
#define UNUSED_ARG(x) (void)x
void sntp_tsk(void *pvParameters)

View file

@ -96,7 +96,7 @@ void test_task(void *pvParameters)
}
while (1) {
vTaskDelay(2000 / portTICK_RATE_MS);
vTaskDelay(2000 / portTICK_PERIOD_MS);
example_write_file();

View file

@ -0,0 +1,3 @@
PROGRAM=SSD1306_Example
EXTRA_COMPONENTS = extras/ssd1306 extras/i2c
include ../../common.mk

View file

@ -0,0 +1,3 @@
# I2C / SSD1306 OLED LCD Example
To run this example connect the SSD1306 OLED LCD and configure SDA/SCL pins in ssd1306_i2c.c file.

View file

@ -0,0 +1,89 @@
#define image_width 128
#define image_height 64
static unsigned char image_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf8, 0xc3, 0xc7, 0x0f, 0x00, 0x1e, 0xfc, 0xf0, 0xe7, 0x30, 0xc0, 0x9f,
0x7f, 0xf0, 0x80, 0x0f, 0x18, 0x30, 0xc4, 0x18, 0x80, 0x61, 0x8c, 0x31,
0xe0, 0x30, 0xc0, 0x38, 0x0c, 0x0c, 0x63, 0x08, 0x18, 0x30, 0xc0, 0x30,
0x80, 0x61, 0x0c, 0x33, 0xe0, 0x31, 0xc0, 0x30, 0x0c, 0x0c, 0x63, 0x00,
0x18, 0xf0, 0xc0, 0x30, 0xc0, 0xc0, 0x0c, 0x33, 0x60, 0x31, 0xc0, 0x30,
0x0c, 0x06, 0xe6, 0x01, 0xf8, 0xe3, 0xc7, 0x30, 0xc0, 0xc0, 0x0c, 0xf3,
0x67, 0x33, 0xc0, 0x38, 0x0c, 0x06, 0xc6, 0x0f, 0x18, 0x80, 0xcf, 0x18,
0xcf, 0xc0, 0x8c, 0x31, 0x60, 0x36, 0xcf, 0x1f, 0x0c, 0x06, 0x06, 0x1f,
0x18, 0x00, 0xce, 0x0f, 0xcf, 0xc0, 0xfc, 0x30, 0x60, 0x36, 0xcf, 0x18,
0x0c, 0x06, 0x06, 0x1c, 0x18, 0x00, 0xcc, 0x00, 0x80, 0x61, 0x0c, 0x30,
0x60, 0x3c, 0xc0, 0x30, 0x0c, 0x0c, 0x03, 0x18, 0x18, 0x10, 0xcc, 0x00,
0x80, 0x61, 0x0c, 0x30, 0x60, 0x38, 0xc0, 0x30, 0x0c, 0x0c, 0x23, 0x18,
0xf8, 0xf3, 0xc3, 0x00, 0x00, 0x1e, 0x0c, 0xf0, 0x67, 0x38, 0xc0, 0x60,
0x0c, 0xf0, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x1f, 0xfc, 0x01, 0x1c, 0xf8, 0x81,
0x0f, 0x78, 0x00, 0x0c, 0x80, 0x1f, 0xfe, 0x00, 0xf0, 0x87, 0x3f, 0xfc,
0x07, 0x1f, 0xfc, 0xc3, 0x1f, 0xfc, 0x00, 0x0c, 0xe0, 0x3f, 0xfe, 0x03,
0x38, 0xc4, 0x21, 0x0c, 0x0e, 0x1b, 0x04, 0xc7, 0x18, 0x8e, 0x00, 0x0c,
0x70, 0x20, 0x06, 0x07, 0x18, 0xc0, 0x00, 0x0c, 0x0c, 0x18, 0x00, 0x66,
0x30, 0x07, 0x00, 0x0c, 0x30, 0x00, 0x06, 0x06, 0x18, 0xc0, 0x00, 0x0c,
0x18, 0x18, 0x00, 0x67, 0x30, 0x03, 0x00, 0x0c, 0x18, 0x00, 0x06, 0x0c,
0xf0, 0x81, 0x0f, 0x0c, 0x18, 0x18, 0xf0, 0x61, 0x30, 0x7b, 0x00, 0x0c,
0x18, 0x00, 0x06, 0x0c, 0xe0, 0x07, 0x3f, 0x0c, 0x18, 0x18, 0xf0, 0x63,
0x30, 0xff, 0x00, 0x0c, 0x18, 0x00, 0x06, 0x0c, 0x00, 0x0e, 0x70, 0x0c,
0x18, 0x18, 0x00, 0x67, 0x30, 0xc7, 0x01, 0x0c, 0x18, 0x00, 0x06, 0x0c,
0x00, 0x0c, 0x60, 0x0c, 0x18, 0x18, 0x00, 0x66, 0x30, 0x83, 0x01, 0x0c,
0x18, 0x00, 0x06, 0x0c, 0x00, 0x0c, 0x60, 0x0c, 0x0c, 0x18, 0x00, 0x66,
0x30, 0x83, 0x01, 0x0c, 0x30, 0x00, 0x06, 0x06, 0x08, 0x4e, 0x70, 0x0c,
0x0e, 0x18, 0x04, 0xc7, 0x18, 0xc6, 0x01, 0x0c, 0x70, 0x20, 0x06, 0x07,
0xf8, 0xc7, 0x3f, 0xfc, 0x07, 0xff, 0xfc, 0xc3, 0x1f, 0xfe, 0x00, 0xfc,
0xe3, 0x3f, 0xfe, 0x03, 0xf0, 0x83, 0x1f, 0xfc, 0x01, 0xff, 0xf8, 0x81,
0x0f, 0x78, 0x00, 0xfc, 0x83, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x18,
0x18, 0x7e, 0xc0, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x01, 0x00, 0x00, 0x18, 0x18, 0xfe, 0x80, 0x61, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x18, 0x18, 0xc6, 0x81, 0x33,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3d, 0x06, 0x06, 0x18,
0x18, 0x86, 0x01, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x7f, 0x06, 0x06, 0x18, 0x18, 0x86, 0x01, 0x1e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xe3, 0x0c, 0x03, 0x18, 0x18, 0xc6, 0x01, 0x0e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc1, 0x0c, 0x03, 0x18,
0x18, 0xfe, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xc1, 0x98, 0x01, 0x18, 0x18, 0x7e, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xc1, 0x98, 0x01, 0x18, 0x18, 0xc6, 0x00, 0x1b,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc1, 0xf0, 0x00, 0x18,
0x18, 0x86, 0x81, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xe3, 0xf0, 0x00, 0x30, 0x0c, 0x86, 0x81, 0x71, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x7f, 0x60, 0x00, 0xf0, 0x0f, 0x06, 0xc3, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3d, 0x60, 0x00, 0xc0,
0x03, 0x06, 0xe7, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };

View file

@ -0,0 +1,65 @@
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include <string.h>
#include "i2c/i2c.h"
#include "ssd1306/ssd1306.h"
#include "image.xbm"
/* Change this according to you schematics */
#define SCL_PIN GPIO_ID_PIN((14))
#define SDA_PIN GPIO_ID_PIN((12))
/* Local frame buffer */
static uint8_t buffer[SSD1306_ROWS * SSD1306_COLS / 8];
static void ssd1306_task(void *pvParameters)
{
printf("%s: Started user interface task\n", __FUNCTION__);
vTaskDelay(1000/portTICK_PERIOD_MS);
if (ssd1306_load_xbm(image_bits, buffer))
goto error_loop;
ssd1306_set_whole_display_lighting(false);
while (1) {
vTaskDelay(2000 / portTICK_PERIOD_MS);
printf("%s: steel alive\n", __FUNCTION__);
}
error_loop:
printf("%s: error while loading framebuffer into SSD1306\n", __func__);
for(;;){
vTaskDelay(2000 / portTICK_PERIOD_MS);
printf("%s: error loop\n", __FUNCTION__);
}
}
void user_init(void)
{
// Setup HW
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());
i2c_init(SCL_PIN, SDA_PIN);
if (ssd1306_init()){
for (;;) {
printf("%s: failed to init SSD1306 lcd\n", __func__);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
ssd1306_set_whole_display_lighting(true);
vTaskDelay(1000/portTICK_PERIOD_MS);
// Create user interface task
xTaskCreate(ssd1306_task, "ssd1306_task", 256, NULL, 2, NULL);
}

View file

@ -59,7 +59,7 @@ static void cmd_help(uint32_t argc, char *argv[])
static void cmd_sleep(uint32_t argc, char *argv[])
{
printf("Type away while I take a 2 second nap (ie. let you test the UART HW FIFO\n");
vTaskDelay(2000 / portTICK_RATE_MS);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
static void handle_command(char *cmd)

View file

@ -56,7 +56,7 @@ void tsl2561MeasurementTask(void *pvParameters)
}
// 0.1 second delay
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

View file

@ -0,0 +1,4 @@
PROGRAM = wifi_scan
#ESPBAUD = 460800
include ../../common.mk

72
examples/wifi_scan/main.c Normal file
View file

@ -0,0 +1,72 @@
/*
* WiFi scan
*
* Part of esp-open-rtos
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#include <esp/uart.h>
#include <stdio.h>
#include <espressif/esp_common.h>
#include <FreeRTOS.h>
#include <task.h>
#include <string.h>
static const char * const auth_modes [] = {
[AUTH_OPEN] = "Open",
[AUTH_WEP] = "WEP",
[AUTH_WPA_PSK] = "WPA/PSK",
[AUTH_WPA2_PSK] = "WPA2/PSK",
[AUTH_WPA_WPA2_PSK] = "WPA/WPA2/PSK"
};
static void scan_done_cb(void *arg, sdk_scan_status_t status)
{
char ssid[33]; // max SSID length + zero byte
if (status != SCAN_OK)
{
printf("Error: WiFi scan failed\n");
return;
}
struct sdk_bss_info *bss = (struct sdk_bss_info *)arg;
// first one is invalid
bss = bss->next.stqe_next;
printf("\n----------------------------------------------------------------------------------\n");
printf(" Wi-Fi networks\n");
printf("----------------------------------------------------------------------------------\n");
while (NULL != bss)
{
size_t len = strlen((const char *)bss->ssid);
memcpy(ssid, bss->ssid, len);
ssid[len] = 0;
printf("%32s (" MACSTR ") RSSI: %02d, security: %s\n", ssid,
MAC2STR(bss->bssid), bss->rssi, auth_modes[bss->authmode]);
bss = bss->next.stqe_next;
}
}
static void scan_task(void *arg)
{
while (true)
{
sdk_wifi_station_scan(NULL, scan_done_cb);
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
void user_init()
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n\n", sdk_system_get_sdk_version());
// We can scan only in station mode
sdk_wifi_set_opmode(STATION_MODE);
xTaskCreate(scan_task, "scan", 512, NULL, 2, NULL);
}

View file

@ -70,7 +70,7 @@ static void demo(void *pvParameters)
sizeof(ws2812_pixel_t));
ws2812_i2s_update(pixels);
vTaskDelay(20 / portTICK_RATE_MS);
vTaskDelay(20 / portTICK_PERIOD_MS);
}
}
}

View file

@ -18,7 +18,7 @@
#include "ws2812.h"
#define delay_ms(ms) vTaskDelay((ms) / portTICK_RATE_MS)
#define delay_ms(ms) vTaskDelay((ms) / portTICK_PERIOD_MS)
/** GPIO number used to control the RGBs */

View file

@ -34,7 +34,7 @@ As all data aqquired from the BMP180/BMP085 is provided to the `bmp180_informUse
```
// Own BMP180 User Inform Implementation
bool my_informUser(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) {
bool my_informUser(const QueueHandle_t* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) {
my_event_t ev;
ev.event_type = MY_EVT_BMP180;

View file

@ -214,20 +214,20 @@ bool bmp180_measure(bmp180_constants_t *c, int32_t *temperature,
typedef struct
{
uint8_t cmd;
const xQueueHandle* resultQueue;
const QueueHandle_t* resultQueue;
} bmp180_command_t;
// Just works due to the fact that xQueueHandle is a "void *"
static xQueueHandle bmp180_rx_queue = NULL;
static xTaskHandle bmp180_task_handle = NULL;
// Just works due to the fact that QueueHandle_t is a "void *"
static QueueHandle_t bmp180_rx_queue = NULL;
static TaskHandle_t bmp180_task_handle = NULL;
//
// Forward declarations
//
static bool bmp180_informUser_Impl(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure);
static bool bmp180_informUser_Impl(const QueueHandle_t* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure);
// Set default implementation .. User gets result as bmp180_result_t event
bool (*bmp180_informUser)(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) = bmp180_informUser_Impl;
bool (*bmp180_informUser)(const QueueHandle_t* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure) = bmp180_informUser_Impl;
// I2C Driver Task
static void bmp180_driver_task(void *pvParameters)
@ -295,7 +295,7 @@ static bool bmp180_createTask()
}
// Default user inform implementation
static bool bmp180_informUser_Impl(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure)
static bool bmp180_informUser_Impl(const QueueHandle_t* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure)
{
bmp180_result_t result;
@ -328,7 +328,7 @@ bool bmp180_init(uint8_t scl, uint8_t sda)
return result;
}
void bmp180_trigger_measurement(const xQueueHandle* resultQueue)
void bmp180_trigger_measurement(const QueueHandle_t* resultQueue)
{
bmp180_command_t c;
@ -339,7 +339,7 @@ void bmp180_trigger_measurement(const xQueueHandle* resultQueue)
}
void bmp180_trigger_pressure_measurement(const xQueueHandle* resultQueue)
void bmp180_trigger_pressure_measurement(const QueueHandle_t* resultQueue)
{
bmp180_command_t c;
@ -349,7 +349,7 @@ void bmp180_trigger_pressure_measurement(const xQueueHandle* resultQueue)
xQueueSend(bmp180_rx_queue, &c, 0);
}
void bmp180_trigger_temperature_measurement(const xQueueHandle* resultQueue)
void bmp180_trigger_temperature_measurement(const QueueHandle_t* resultQueue)
{
bmp180_command_t c;

View file

@ -45,16 +45,16 @@ typedef struct
bool bmp180_init(uint8_t scl, uint8_t sda);
// Trigger a "complete" measurement (temperature and pressure will be valid when given to "bmp180_informUser)
void bmp180_trigger_measurement(const xQueueHandle* resultQueue);
void bmp180_trigger_measurement(const QueueHandle_t* resultQueue);
// Trigger a "temperature only" measurement (only temperature will be valid when given to "bmp180_informUser)
void bmp180_trigger_temperature_measurement(const xQueueHandle* resultQueue);
void bmp180_trigger_temperature_measurement(const QueueHandle_t* resultQueue);
// Trigger a "pressure only" measurement (only pressure will be valid when given to "bmp180_informUser)
void bmp180_trigger_pressure_measurement(const xQueueHandle* resultQueue);
void bmp180_trigger_pressure_measurement(const QueueHandle_t* resultQueue);
// Give the user the chance to create it's own handler
extern bool (*bmp180_informUser)(const xQueueHandle* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure);
extern bool (*bmp180_informUser)(const QueueHandle_t* resultQueue, uint8_t cmd, bmp180_temp_t temperature, bmp180_press_t pressure);
// Calibration constants
typedef struct

View file

@ -72,7 +72,7 @@ while(1) {
printf("Pressure: %.2f Pa, Temperature: %.2f C", pressure, temperature);
if (bme280p)
printf(", Humidity: %.2f\n", humidity);
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
```
@ -96,7 +96,7 @@ while(1) {
printf(", Humidity: %.2f\n", humidity);
else
printf("\n");
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
```

View file

@ -35,7 +35,7 @@
namespace esp_open_rtos {
namespace timer {
#define __millis() (xTaskGetTickCount() * portTICK_RATE_MS)
#define __millis() (xTaskGetTickCount() * portTICK_PERIOD_MS)
/******************************************************************************************************************
* countdown_t
@ -93,7 +93,7 @@ public:
}
private:
portTickType interval_end_ms;
TickType_t interval_end_ms;
};
} // namespace timer {

View file

@ -86,7 +86,7 @@ public:
*/
inline int try_lock(unsigned long ms)
{
return (xSemaphoreTake(mutex, ms / portTICK_RATE_MS) == pdTRUE) ? 0 : -1;
return (xSemaphoreTake(mutex, ms / portTICK_PERIOD_MS) == pdTRUE) ? 0 : -1;
}
/**
*
@ -98,7 +98,7 @@ public:
}
private:
xSemaphoreHandle mutex;
SemaphoreHandle_t mutex;
// Disable copy construction and assignment.
mutex_t (const mutex_t&);

View file

@ -83,7 +83,7 @@ public:
*/
inline int post(const Data& data, unsigned long ms = 0)
{
return (xQueueSend(queue, &data, ms / portTICK_RATE_MS) == pdTRUE) ? 0 : -1;
return (xQueueSend(queue, &data, ms / portTICK_PERIOD_MS) == pdTRUE) ? 0 : -1;
}
/**
*
@ -93,7 +93,7 @@ public:
*/
inline int receive(Data& data, unsigned long ms = 0)
{
return (xQueueReceive(queue, &data, ms / portTICK_RATE_MS) == pdTRUE) ? 0 : -1;
return (xQueueReceive(queue, &data, ms / portTICK_PERIOD_MS) == pdTRUE) ? 0 : -1;
}
/**
*
@ -110,7 +110,7 @@ public:
}
private:
xQueueHandle queue;
QueueHandle_t queue;
// Disable copy construction.
queue_t (const queue_t&);

View file

@ -66,7 +66,7 @@ protected:
*/
void sleep(unsigned long ms)
{
vTaskDelay(ms / portTICK_RATE_MS);
vTaskDelay(ms / portTICK_PERIOD_MS);
}
/**
*
@ -74,7 +74,7 @@ protected:
*/
inline unsigned long millis()
{
return xTaskGetTickCount() * portTICK_RATE_MS;
return xTaskGetTickCount() * portTICK_PERIOD_MS;
}
private:

View file

@ -49,7 +49,7 @@ typedef struct {
/* Only one DHCP server task can run at once, so we have global state
for it.
*/
static xTaskHandle dhcpserver_task_handle;
static TaskHandle_t dhcpserver_task_handle = NULL;
static server_state_t *state;
/* Handlers for various kinds of incoming DHCP messages */
@ -108,7 +108,7 @@ static void dhcpserver_task(void *pxParameter)
state->nc = netconn_new (NETCONN_UDP);
if(!state->nc) {
printf("OTA TFTP: Failed to allocate socket.\r\n");
printf("DHCP Server Error: Failed to allocate socket.\r\n");
return;
}

View file

@ -1,10 +1,10 @@
# Component makefile for extras/dht
INC_DIRS += $(ROOT)extras/dht
# include it as 'dht/dht.h'
INC_DIRS += $(dht_ROOT)..
# args for passing into compile rule generation
extras/dht_INC_DIR = $(ROOT)extras/dht
extras/dht_SRC_DIR = $(ROOT)extras/dht
dht_SRC_DIR = $(dht_ROOT)
$(eval $(call component_compile_rules,extras/dht))
$(eval $(call component_compile_rules,dht))

View file

@ -14,11 +14,10 @@
#include <espressif/esp_misc.h> // sdk_os_delay_us
// DHT timer precision in microseconds
#define DHT_TIMER_INTERVAL 2
#define DHT_DATA_BITS 40
#define DHT_TIMER_INTERVAL 2
#define DHT_DATA_BITS 40
// #define DEBUG_DHT
#ifdef DEBUG_DHT
#define debug(fmt, ...) printf("%s" fmt "\n", "dht: ", ## __VA_ARGS__);
#else
@ -116,7 +115,7 @@ static inline bool dht_fetch_data(uint8_t pin, bool bits[DHT_DATA_BITS])
debug("LOW bit timeout\n");
return false;
}
if (!dht_await_pin_state(pin, 75, false, &high_duration)){
if (!dht_await_pin_state(pin, 75, false, &high_duration)) {
debug("HIGHT bit timeout\n");
return false;
}
@ -128,27 +127,26 @@ static inline bool dht_fetch_data(uint8_t pin, bool bits[DHT_DATA_BITS])
/**
* Pack two data bytes into single value and take into account sign bit.
*/
static inline int16_t dht_convert_data(uint8_t msb, uint8_t lsb)
static inline int16_t dht_convert_data(dht_sensor_type_t sensor_type, uint8_t msb, uint8_t lsb)
{
int16_t data;
#if DHT_TYPE == DHT22
data = msb & 0x7F;
data <<= 8;
data |= lsb;
if (msb & BIT(7)) {
data = 0 - data; // convert it to negative
if (sensor_type == DHT_TYPE_DHT22) {
data = msb & 0x7F;
data <<= 8;
data |= lsb;
if (msb & BIT(7)) {
data = 0 - data; // convert it to negative
}
}
else {
data = msb * 10;
}
#elif DHT_TYPE == DHT11
data = msb * 10;
#else
#error "Unsupported DHT type"
#endif
return data;
}
bool dht_read_data(uint8_t pin, int16_t *humidity, int16_t *temperature)
bool dht_read_data(dht_sensor_type_t sensor_type, uint8_t pin, int16_t *humidity, int16_t *temperature)
{
bool bits[DHT_DATA_BITS];
uint8_t data[DHT_DATA_BITS/8] = {0};
@ -175,19 +173,19 @@ bool dht_read_data(uint8_t pin, int16_t *humidity, int16_t *temperature)
return false;
}
*humidity = dht_convert_data(data[0], data[1]);
*temperature = dht_convert_data(data[2], data[3]);
*humidity = dht_convert_data(sensor_type, data[0], data[1]);
*temperature = dht_convert_data(sensor_type, data[2], data[3]);
debug("Sensor data: humidity=%d, temp=%d\n", *humidity, *temperature);
return true;
}
bool dht_read_float_data(uint8_t pin, float *humidity, float *temperature)
bool dht_read_float_data(dht_sensor_type_t sensor_type, uint8_t pin, float *humidity, float *temperature)
{
int16_t i_humidity, i_temp;
if (dht_read_data(pin, &i_humidity, &i_temp)) {
if (dht_read_data(sensor_type, pin, &i_humidity, &i_temp)) {
*humidity = (float)i_humidity / 10;
*temperature = (float)i_temp / 10;
return true;

View file

@ -11,16 +11,19 @@
#include <stdint.h>
#include <stdbool.h>
#define DHT11 11
#define DHT22 22
// Type of sensor to use
#define DHT_TYPE DHT22
#ifdef __cplusplus
extern "C" {
#endif
/**
* Sensor type
*/
typedef enum
{
DHT_TYPE_DHT11 = 0, //!< DHT11
DHT_TYPE_DHT22 //!< DHT22
} dht_sensor_type_t;
/**
* Read data from sensor on specified pin.
*
@ -29,7 +32,7 @@ extern "C" {
* temperature=24.4 is 24.4 degrees Celsius
*
*/
bool dht_read_data(uint8_t pin, int16_t *humidity, int16_t *temperature);
bool dht_read_data(dht_sensor_type_t sensor_type, uint8_t pin, int16_t *humidity, int16_t *temperature);
/**
@ -37,7 +40,7 @@ bool dht_read_data(uint8_t pin, int16_t *humidity, int16_t *temperature);
*
* Return values as floating point values.
*/
bool dht_read_float_data(uint8_t pin, float *humidity, float *temperature);
bool dht_read_float_data(dht_sensor_type_t sensor_type, uint8_t pin, float *humidity, float *temperature);
#ifdef __cplusplus
}

View file

@ -0,0 +1,9 @@
# Component makefile for extras/ds1302
# expected anyone using RTC driver includes it as 'ds1302/ds1302.h'
INC_DIRS += $(ds1302_ROOT)..
# args for passing into compile rule generation
ds1302_SRC_DIR = $(ds1302_ROOT)
$(eval $(call component_compile_rules,ds1302))

232
extras/ds1302/ds1302.c Normal file
View file

@ -0,0 +1,232 @@
/*
* Driver for DS1302 RTC
*
* Part of esp-open-rtos
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>,
* Pavel Merzlyakov <merzlyakovpavel@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#include "ds1302.h"
#include <esp/gpio.h>
#include <espressif/esp_common.h>
#define CH_REG 0x80
#define WP_REG 0x8e
#define CH_BIT (1 << 7)
#define WP_BIT (1 << 7)
#define HOUR12_BIT (1 << 7)
#define PM_BIT (1 << 5)
#define CH_MASK ((uint8_t)(~CH_BIT))
#define WP_MASK ((uint8_t)(~WP_BIT))
#define CLOCK_BURST 0xbe
#define RAM_BURST 0xfe
#define SECONDS_MASK 0x7f
#define HOUR12_MASK 0x1f
#define HOUR24_MASK 0x3f
static uint8_t _ce_pin;
static uint8_t _io_pin;
static uint8_t _sclk_pin;
static bool _wp;
static uint8_t _ch;
static uint8_t bcd2dec(uint8_t val)
{
return (val >> 4) * 10 + (val & 0x0f);
}
static uint8_t dec2bcd(uint8_t val)
{
return ((val / 10) << 4) + (val % 10);
}
inline static void chip_enable()
{
gpio_write(_ce_pin, true);
sdk_os_delay_us(4);
}
inline static void chip_disable()
{
gpio_write(_ce_pin, false);
}
inline static void prepare(gpio_direction_t dir)
{
gpio_enable(_io_pin, dir);
gpio_write(_sclk_pin, false);
chip_enable();
}
inline static void toggle_clock()
{
gpio_write(_sclk_pin, true);
sdk_os_delay_us(1);
gpio_write(_sclk_pin, false);
sdk_os_delay_us(1);
}
static void write_byte(uint8_t b)
{
for (uint8_t i = 0; i < 8; i++)
{
gpio_write(_io_pin, (b >> i) & 1);
toggle_clock();
}
}
static uint8_t read_byte()
{
uint8_t b = 0;
for (uint8_t i = 0; i < 8; i++)
{
b |= gpio_read(_io_pin) << i;
toggle_clock();
}
return b;
}
static uint8_t read_register(uint8_t reg)
{
prepare(GPIO_OUTPUT);
write_byte(reg | 0x01);
prepare(GPIO_INPUT);
uint8_t res = read_byte();
chip_disable();
return res;
}
static void write_register(uint8_t reg, uint8_t val)
{
prepare(GPIO_OUTPUT);
write_byte(reg);
write_byte(val);
chip_disable();
}
static void burst_read(uint8_t reg, uint8_t *dst, uint8_t len)
{
prepare(GPIO_OUTPUT);
write_byte(reg | 0x01);
prepare(GPIO_INPUT);
for (uint8_t i = 0; i < len; i++, dst++)
*dst = read_byte();
chip_disable();
}
static void burst_write(uint8_t reg, uint8_t *src, uint8_t len)
{
prepare(GPIO_OUTPUT);
write_byte(reg);
for (uint8_t i = 0; i < len; i++, src++)
write_byte(*src);
chip_disable();
}
inline static void update_register(uint8_t reg, uint8_t mask, uint8_t val)
{
write_register(reg, (read_register(reg) & mask) | val);
}
void ds1302_init(uint8_t ce_pin, uint8_t io_pin, uint8_t sclk_pin)
{
_ce_pin = ce_pin;
_io_pin = io_pin;
_sclk_pin = sclk_pin;
gpio_enable(_ce_pin, GPIO_OUTPUT);
gpio_enable(_sclk_pin, GPIO_OUTPUT);
_wp = ds1302_get_write_protect();
_ch = read_register(CH_REG) & CH_BIT;
}
bool ds1302_start(bool start)
{
if (_wp) return false;
_ch = start ? 0 : CH_BIT;
update_register(CH_REG, CH_MASK, _ch);
return true;
}
bool ds1302_is_running()
{
return !(read_register(CH_REG) & CH_BIT);
}
void ds1302_set_write_protect(bool protect)
{
update_register(WP_REG, WP_MASK, protect ? WP_BIT : 0);
_wp = protect;
}
bool ds1302_get_write_protect()
{
return (read_register(WP_REG) & WP_BIT) != 0;
}
void ds1302_get_time(struct tm *time)
{
uint8_t buf[7];
burst_read(CLOCK_BURST, buf, 7);
time->tm_sec = bcd2dec(buf[0] & SECONDS_MASK);
time->tm_min = bcd2dec(buf[1]);
if (buf[2] & HOUR12_BIT)
{
// RTC in 12-hour mode
time->tm_hour = bcd2dec(buf[2] & HOUR12_MASK) - 1;
if (buf[2] & PM_BIT)
time->tm_hour += 12;
}
else time->tm_hour = bcd2dec(buf[2] & HOUR24_MASK);
time->tm_mday = bcd2dec(buf[3]);
time->tm_mon = bcd2dec(buf[4]) - 1;
time->tm_wday = bcd2dec(buf[5]) - 1;
time->tm_year = bcd2dec(buf[6]) + 2000;
}
bool ds1302_set_time(const struct tm *time)
{
if (_wp) return false;
uint8_t buf[8] = {
dec2bcd(time->tm_sec) | _ch,
dec2bcd(time->tm_min),
dec2bcd(time->tm_hour),
dec2bcd(time->tm_mday),
dec2bcd(time->tm_mon + 1),
dec2bcd(time->tm_wday + 1),
dec2bcd(time->tm_year - 2000),
0
};
burst_write(CLOCK_BURST, buf, 8);
return true;
}
bool ds1302_read_sram(uint8_t offset, void *buf, uint8_t len)
{
if (offset + len > DS1302_RAM_SIZE)
return false;
burst_read(RAM_BURST, (uint8_t *)buf, len);
return true;
}
bool ds1302_write_sram(uint8_t offset, void *buf, uint8_t len)
{
if (offset + len > DS1302_RAM_SIZE)
return false;
burst_write(RAM_BURST, (uint8_t *)buf, len);
return true;
}

84
extras/ds1302/ds1302.h Normal file
View file

@ -0,0 +1,84 @@
/*
* Driver for DS1302 RTC
*
* Part of esp-open-rtos
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>,
* Pavel Merlyakov <merzlyakovpavel@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#ifndef EXTRAS_DS1302_H_
#define EXTRAS_DS1302_H_
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
#define DS1302_RAM_SIZE 31
void ds1302_init(uint8_t ce_pin, uint8_t io_pin, uint8_t sclk_pin);
/**
* \brief Start/stop clock
* \param start Start clock if true
* \return False if RTC is write-protected
*/
bool ds1302_start(bool start);
/**
* \brief Get current clock state
* \return true if clock running
*/
bool ds1302_is_running();
/**
* \brief Enable/disable write protection
* \param protect Set RTC write-protected if true
*/
void ds1302_set_write_protect(bool protect);
/**
* \brief Get write protection status
* \return true if RTC write-protected
*/
bool ds1302_get_write_protect();
/**
* \brief Get current time
* \param time Pointer to the time struct to fill
*/
void ds1302_get_time(struct tm *time);
/**
* \brief Set time to RTC
* \param time Pointer to the time struct
* \return False if RTC is write-protected
*/
bool ds1302_set_time(const struct tm *time);
/**
* \brief Read RAM contents into the buffer
* \param offset Start byte, 0..55
* \param buf Buffer
* \param len Bytes to read, 1..56
* \return false if error occured (invalid offset or buffer too big)
*/
bool ds1302_read_sram(uint8_t offset, void *buf, uint8_t len);
/**
* \brief Write buffer to RTC RAM
* \param offset Start byte, 0..55
* \param buf Buffer
* \param len Bytes to write, 1..56
* \return false if error occured (invalid offset or buffer too big)
*/
bool ds1302_write_sram(uint8_t offset, void *buf, uint8_t len);
#ifdef __cplusplus
}
#endif
#endif /* EXTRAS_DS1302_H_ */

View file

@ -78,14 +78,14 @@ void ds1307_get_time(struct tm *time)
if (buf[2] & HOUR12_BIT)
{
// RTC in 12-hour mode
time->tm_hour = bcd2dec(buf[2] & HOUR12_MASK);
time->tm_hour = bcd2dec(buf[2] & HOUR12_MASK) - 1;
if (buf[2] & PM_BIT)
time->tm_hour += 12;
}
else time->tm_hour = bcd2dec(buf[2] & HOUR24_MASK);
time->tm_wday = bcd2dec(buf[3]) - 1;
time->tm_mday = bcd2dec(buf[4]);
time->tm_mon = bcd2dec(buf[5]);
time->tm_mon = bcd2dec(buf[5]) - 1;
time->tm_year = bcd2dec(buf[6]) + 2000;
}
@ -96,9 +96,9 @@ void ds1307_set_time(const struct tm *time)
buf[1] = dec2bcd(time->tm_sec);
buf[2] = dec2bcd(time->tm_min);
buf[3] = dec2bcd(time->tm_hour);
buf[4] = dec2bcd(time->tm_wday);
buf[4] = dec2bcd(time->tm_wday + 1);
buf[5] = dec2bcd(time->tm_mday);
buf[6] = dec2bcd(time->tm_mon);
buf[6] = dec2bcd(time->tm_mon + 1);
buf[7] = dec2bcd(time->tm_year - 2000);
i2c_slave_write(ADDR, buf, 8);

View file

@ -6,4 +6,10 @@ INC_DIRS += $(ds18b20_ROOT)..
# args for passing into compile rule generation
ds18b20_SRC_DIR = $(ds18b20_ROOT)
# users can override this setting and get console debug output
DS18B20_DEBUG ?= 0
ifeq ($(DS18B20_DEBUG),1)
ds18b20_CFLAGS = $(CFLAGS) -DDS18B20_DEBUG
endif
$(eval $(call component_compile_rules,ds18b20))

View file

@ -16,7 +16,16 @@
#define DS18B20_ALARMSEARCH 0xEC
#define DS18B20_CONVERT_T 0x44
#define os_sleep_ms(x) vTaskDelay(((x) + portTICK_RATE_MS - 1) / portTICK_RATE_MS)
#define os_sleep_ms(x) vTaskDelay(((x) + portTICK_PERIOD_MS - 1) / portTICK_PERIOD_MS)
#define DS18B20_FAMILY_ID 0x28
#define DS18S20_FAMILY_ID 0x10
#ifdef DS18B20_DEBUG
#define debug(fmt, ...) printf("%s" fmt "\n", "DS18B20: ", ## __VA_ARGS__);
#else
#define debug(fmt, ...)
#endif
uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
onewire_addr_t addr;
@ -28,7 +37,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
while ((addr = onewire_search_next(&search, pin)) != ONEWIRE_NONE) {
uint8_t crc = onewire_crc8((uint8_t *)&addr, 7);
if (crc != (addr >> 56)){
printf("CRC check failed: %02X %02X\n", (unsigned)(addr >> 56), crc);
debug("CRC check failed: %02X %02X\n", (unsigned)(addr >> 56), crc);
return 0;
}
@ -37,7 +46,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
onewire_write(pin, DS18B20_CONVERT_T);
onewire_power(pin);
vTaskDelay(750 / portTICK_RATE_MS);
vTaskDelay(750 / portTICK_PERIOD_MS);
onewire_reset(pin);
onewire_select(pin, addr);
@ -49,11 +58,11 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
get[k]=onewire_read(pin);
}
//printf("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);
//debug("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);
crc = onewire_crc8(get, 8);
if (crc != get[8]){
printf("CRC check failed: %02X %02X\n", get[8], crc);
debug("CRC check failed: %02X %02X\n", get[8], crc);
return 0;
}
@ -64,7 +73,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
float temperature;
temperature = (temp * 625.0)/10000;
//printf("Got a DS18B20 Reading: %d.%02d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
//debug("Got a DS18B20 Reading: %d.%02d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
result[sensor_id].id = sensor_id;
result[sensor_id].value = temperature;
sensor_id++;
@ -79,7 +88,7 @@ float ds18b20_read_single(uint8_t pin) {
onewire_write(pin, DS18B20_CONVERT_T);
onewire_power(pin);
vTaskDelay(750 / portTICK_RATE_MS);
vTaskDelay(750 / portTICK_PERIOD_MS);
onewire_reset(pin);
onewire_skip_rom(pin);
@ -91,11 +100,11 @@ float ds18b20_read_single(uint8_t pin) {
get[k]=onewire_read(pin);
}
//printf("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);
//debug("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);
uint8_t crc = onewire_crc8(get, 8);
if (crc != get[8]){
printf("CRC check failed: %02X %02X", get[8], crc);
debug("CRC check failed: %02X %02X", get[8], crc);
return 0;
}
@ -108,7 +117,7 @@ float ds18b20_read_single(uint8_t pin) {
temperature = (temp * 625.0)/10000;
return temperature;
//printf("Got a DS18B20 Reading: %d.%02d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
//debug("Got a DS18B20 Reading: %d.%02d\n", (int)temperature, (int)(temperature - (int)temperature) * 100);
}
bool ds18b20_measure(int pin, ds18b20_addr_t addr, bool wait) {
@ -156,7 +165,7 @@ bool ds18b20_read_scratchpad(int pin, ds18b20_addr_t addr, uint8_t *buffer) {
expected_crc = onewire_crc8(buffer, 8);
if (crc != expected_crc) {
printf("CRC check failed reading scratchpad: %02x %02x %02x %02x %02x %02x %02x %02x : %02x (expected %02x)\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], crc, expected_crc);
debug("CRC check failed reading scratchpad: %02x %02x %02x %02x %02x %02x %02x %02x : %02x (expected %02x)\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], crc, expected_crc);
return false;
}
@ -172,8 +181,16 @@ float ds18b20_read_temperature(int pin, ds18b20_addr_t addr) {
}
temp = scratchpad[1] << 8 | scratchpad[0];
return ((float)temp * 625.0)/10000;
float res;
if ((uint8_t)addr == DS18B20_FAMILY_ID) {
res = ((float)temp * 625.0)/10000;
}
else {
temp = ((temp & 0xfffe) << 3) + (16 - scratchpad[6]) - 4;
res = ((float)temp * 625.0)/10000 - 0.25;
}
return res;
}
float ds18b20_measure_and_read(int pin, ds18b20_addr_t addr) {
@ -200,10 +217,13 @@ int ds18b20_scan_devices(int pin, ds18b20_addr_t *addr_list, int addr_count) {
onewire_search_start(&search);
while ((addr = onewire_search_next(&search, pin)) != ONEWIRE_NONE) {
if (found < addr_count) {
addr_list[found] = addr;
uint8_t family_id = (uint8_t)addr;
if (family_id == DS18B20_FAMILY_ID || family_id == DS18S20_FAMILY_ID) {
if (found < addr_count) {
addr_list[found] = addr;
}
found++;
}
found++;
}
return found;
}

View file

@ -270,7 +270,7 @@ bool ds3231_getTime(struct tm *time)
time->tm_min = bcdToDec(data[1]);
if (data[2] & DS3231_12HOUR_FLAG) {
/* 12H */
time->tm_hour = bcdToDec(data[2] & DS3231_12HOUR_MASK);
time->tm_hour = bcdToDec(data[2] & DS3231_12HOUR_MASK) - 1;
/* AM/PM? */
if (data[2] & DS3231_PM_FLAG) time->tm_hour += 12;
} else {

View file

@ -275,7 +275,7 @@
#ifndef _FS_TIMEOUT
#define _FS_TIMEOUT 1000
#endif
#define _SYNC_t xSemaphoreHandle
#define _SYNC_t SemaphoreHandle_t
/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()

View file

@ -13,7 +13,7 @@
* synchronization object, such as semaphore and mutex. When a 0 is returned,
* the f_mount() function fails with FR_INT_ERR.
*/
int ff_cre_syncobj(BYTE vol, xSemaphoreHandle *sobj)
int ff_cre_syncobj(BYTE vol, SemaphoreHandle_t *sobj)
{
int ret;
@ -29,7 +29,7 @@ int ff_cre_syncobj(BYTE vol, xSemaphoreHandle *sobj)
* object that created with ff_cre_syncobj() function. When a 0 is returned,
* the f_mount() function fails with FR_INT_ERR.
*/
int ff_del_syncobj(xSemaphoreHandle sobj)
int ff_del_syncobj(SemaphoreHandle_t sobj)
{
vSemaphoreDelete(sobj);
return 1;
@ -40,7 +40,7 @@ int ff_del_syncobj(xSemaphoreHandle sobj)
* This function is called on entering file functions to lock the volume.
* When a 0 is returned, the file function fails with FR_TIMEOUT.
*/
int ff_req_grant(xSemaphoreHandle sobj)
int ff_req_grant(SemaphoreHandle_t sobj)
{
return (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE);
}
@ -49,7 +49,7 @@ int ff_req_grant(xSemaphoreHandle sobj)
* Release Grant to Access the Volume
* This function is called on leaving file functions to unlock the volume.
*/
void ff_rel_grant(xSemaphoreHandle sobj)
void ff_rel_grant(SemaphoreHandle_t sobj)
{
xSemaphoreGive(sobj);
}

119
extras/hd44780/README.md Normal file
View file

@ -0,0 +1,119 @@
# HD44780 LCD display driver
## Connection type
Driver supports GPIO connections to module and I2C GPIO expanders as well.
Define `HD44780_I2C = 0` in application makefile for direct GPIO connection.
See `examples/i2c_lcd_test` and `examples/hd44780_test` .
## Display types
### 8x1
#### Memory layout
![0801 display](img/0801.png)
#### Example
```C
hd44780_t lcd = {
.addr = ADDR,
.font = HD44780_FONT_5X8,
.lines = 1,
.pins = {
.rs = 0,
.e = 2,
.d4 = 4,
.d5 = 5,
.d6 = 6,
.d7 = 7,
.bl = 3
},
.backlight = true
};
```
### 16x1
#### Memory layout
![1601 display](img/1601.png)
#### Example
```C
hd44780_t lcd = {
.addr = ADDR,
.font = HD44780_FONT_5X8,
.lines = 2,
.pins = {
.rs = 0,
.e = 2,
.d4 = 4,
.d5 = 5,
.d6 = 6,
.d7 = 7,
.bl = 3
},
.backlight = true
};
hd44780_init(&lcd);
hd44780_gotoxy(&lcd, 0, 0);
hd44780_puts(&lcd, "Hello wo");
hd44780_gotoxy(&lcd, 0, 1);
hd44780_puts(&lcd, "rld!");
```
### 16x2, 20x2
#### Memory layout
![1602 display](img/1602.png)
#### Example
```C
hd44780_t lcd = {
.addr = ADDR,
.font = HD44780_FONT_5X8,
.lines = 2,
.pins = {
.rs = 0,
.e = 2,
.d4 = 4,
.d5 = 5,
.d6 = 6,
.d7 = 7,
.bl = 3
},
.backlight = true
};
```
### 16x4, 20x4
#### Memory layout
![1604 display](img/1604.png)
#### Example
```C
hd44780_t lcd = {
.addr = ADDR,
.font = HD44780_FONT_5X8,
.lines = 2,
.pins = {
.rs = 0,
.e = 2,
.d4 = 4,
.d5 = 5,
.d6 = 6,
.d7 = 7,
.bl = 3
},
.backlight = true
};
```

BIN
extras/hd44780/img/0801.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
extras/hd44780/img/1601.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
extras/hd44780/img/1602.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
extras/hd44780/img/1604.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -30,7 +30,7 @@
char mqtt_timer_expired(mqtt_timer_t* timer)
{
portTickType now = xTaskGetTickCount();
TickType_t now = xTaskGetTickCount();
int32_t left = timer->end_time - now;
return (left < 0);
}
@ -38,8 +38,8 @@ char mqtt_timer_expired(mqtt_timer_t* timer)
void mqtt_timer_countdown_ms(mqtt_timer_t* timer, unsigned int timeout)
{
portTickType now = xTaskGetTickCount();
timer->end_time = now + timeout / portTICK_RATE_MS;
TickType_t now = xTaskGetTickCount();
timer->end_time = now + timeout / portTICK_PERIOD_MS;
}
@ -51,9 +51,9 @@ void mqtt_timer_countdown(mqtt_timer_t* timer, unsigned int timeout)
int mqtt_timer_left_ms(mqtt_timer_t* timer)
{
portTickType now = xTaskGetTickCount();
TickType_t now = xTaskGetTickCount();
int32_t left = timer->end_time - now;
return (left < 0) ? 0 : left / portTICK_RATE_MS;
return (left < 0) ? 0 : left / portTICK_PERIOD_MS;
}
@ -73,7 +73,7 @@ int mqtt_esp_read(mqtt_network_t* n, unsigned char* buffer, int len, int timeou
FD_ZERO(&fdset);
FD_SET(n->my_socket, &fdset);
// It seems tv_sec actually means FreeRTOS tick
tv.tv_sec = timeout_ms / portTICK_RATE_MS;
tv.tv_sec = timeout_ms / portTICK_PERIOD_MS;
tv.tv_usec = 0;
rc = select(n->my_socket + 1, &fdset, 0, 0, &tv);
if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset)))
@ -98,7 +98,7 @@ int mqtt_esp_write(mqtt_network_t* n, unsigned char* buffer, int len, int timeo
FD_ZERO(&fdset);
FD_SET(n->my_socket, &fdset);
// It seems tv_sec actually means FreeRTOS tick
tv.tv_sec = timeout_ms / portTICK_RATE_MS;
tv.tv_sec = timeout_ms / portTICK_PERIOD_MS;
tv.tv_usec = 0;
rc = select(n->my_socket + 1, 0, &fdset, 0, &tv);
if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset)))

View file

@ -28,7 +28,7 @@ typedef struct mqtt_timer mqtt_timer_t;
struct mqtt_timer
{
portTickType end_time;
TickType_t end_time;
};
typedef struct mqtt_network mqtt_network_t;

View file

@ -141,21 +141,16 @@ long _write_r(struct _reent *r, int fd, const char *ptr, int len )
return len;
}
// This function is weakly defined in core/newlib_syscalls.c
long _read_stdin_r(struct _reent *r, int fd, char *ptr, int len);
// This implementation replaces implementation in core/newlib_syscals.c
long _read_r( struct _reent *r, int fd, char *ptr, int len )
{
int ch, i;
if(fd != r->_stdin->_file) {
return SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
}
uart_rxfifo_wait(0, 1);
for(i = 0; i < len; i++) {
ch = uart_getc_nowait(0);
if (ch < 0) break;
ptr[i] = ch;
}
return i;
return _read_stdin_r(r, fd, ptr, len);
}
int _open_r(struct _reent *r, const char *pathname, int flags, int mode)

2
extras/spiffs/mkspiffs/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/mkspiffs
/*.o

22
extras/ssd1306/LICENSE Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Frank Bargstedt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

27
extras/ssd1306/README.md Normal file
View file

@ -0,0 +1,27 @@
# Driver for I2C SSD1306 128x64 OLED LCD
This driver is written for usage with the ESP8266 and FreeRTOS ([esp-open-rtos](https://github.com/SuperHouse/esp-open-rtos)).
### Usage
Before using the SSD1306 LCD module, the function `i2c_init(SCL_PIN, SDA_PIN)` needs to be called to setup the I2C interface and then you must call ssd1306_init().
#### Example
```
#define SCL_PIN GPIO_ID_PIN(0)
#define SDA_PIN GPIO_ID_PIN(2)
...
i2c_init(SCL_PIN, SDA_PIN);
if (ssd1306_init()) {
// An error occured, while performing SSD1306 init init (E.g device not found etc.)
}
// rest of the code
```

View file

@ -0,0 +1,9 @@
# Component makefile for extras/ssd1306
# expected anyone using ssd1306 driver includes it as 'ssd1306/ssd1306.h'
INC_DIRS += $(ssd1306_ROOT)..
# args for passing into compile rule generation
ssd1306_SRC_DIR = $(ssd1306_ROOT)
$(eval $(call component_compile_rules,ssd1306))

376
extras/ssd1306/ssd1306.c Normal file
View file

@ -0,0 +1,376 @@
#include <stdio.h>
#include <i2c/i2c.h>
#include <FreeRTOS.h>
#include <task.h>
#include "ssd1306.h"
/* SSD1306 commands */
#define SSD1306_SET_MEM_ADDR_MODE (0x20)
#define SSD1306_ADDR_MODE_HORIZ (0x0)
#define SSD1306_ADDR_MODE_VERT (0x1)
#define SSD1306_ADDR_MODE_PAGE (0x2)
#define SSD1306_SET_COL_ADDR (0x21)
#define SSD1306_SET_PAGE_ADDR (0x22)
#define SSD1306_SET_DISP_START_LINE (0x40)
#define SSD1306_SET_CONTRAST (0x81)
#define SSD1306_SET_SEGMENT_REMAP0 (0xA0)
#define SSD1306_SET_SEGMENT_REMAP1 (0xA1)
#define SSD1306_SET_ENTIRE_DISP_ON (0xA5)
#define SSD1306_SET_ENTIRE_DISP_OFF (0xA4)
#define SSD1306_SET_INVERSION_OFF (0xA6)
#define SSD1306_SET_INVERSION_ON (0xA7)
#define SSD1306_SET_MUX_RATIO (0xA8)
#define SSD1306_MUX_RATIO_MASK (0x3F)
#define SSD1306_SET_DISPLAY_OFF (0xAE)
#define SSD1306_SET_DISPLAY_ON (0xAF)
#define SSD1306_SET_SCAN_DIR_FWD (0xC0)
#define SSD1306_SET_SCAN_DIR_BWD (0xC8)
#define SSD1306_SET_DISPLAY_OFFSET (0xD3)
#define SSD1306_SET_OSC_FREQ (0xD5)
#define SSD1306_SET_PRE_CHRG_PER (0xD9)
#define SSD1306_SET_COM_PINS_HW_CFG (0xDA)
#define SSD1306_COM_PINS_HW_CFG_MASK (0x32)
#define SSD1306_SEQ_COM_PINS_CFG (0x02)
#define SSD1306_ALT_COM_PINS_CFG (0x12)
#define SSD1306_COM_LR_REMAP_OFF (0x02)
#define SSD1306_COM_LR_REMAP_ON (0x22)
#define SSD1306_SET_DESEL_LVL (0xDB)
#define SSD1306_SET_NOP (0xE3)
#define SSD1306_SET_CHARGE_PUMP (0x8D)
#define SSD1306_CHARGE_PUMP_EN (0x14)
#define SSD1306_CHARGE_PUMP_DIS (0x10)
#ifdef SSD1306_DEBUG
#define debug(fmt, ...) printf("%s" fmt "\n", "SSD1306", ## __VA_ARGS__);
#else
#define debug(fmt, ...)
#endif
/* Issue a command to SSD1306 device
* format such follows:
* |S|Slave Address|W|ACK|0x00|Command|Ack|P|
*
* in case of two-bytes command here will be Data byte
* right after command byte.
*/
int ssd1306_command(uint8_t cmd)
{
i2c_start();
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(0x00)) {
debug("Error while xmitting transmission type\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(cmd)) {
debug("Error while xmitting command: 0x%02X\n", cmd);
i2c_stop();
return -EIO;
}
i2c_stop();
return 0;
}
/* Perform default init routine according
* to SSD1306 datasheet from adafruit.com */
int ssd1306_init()
{
if (!ssd1306_display_on(false) &&
!ssd1306_set_osc_freq(0x80) &&
!ssd1306_set_mux_ratio(SSD1306_ROWS-1) &&
!ssd1306_set_display_offset(0x0) &&
!ssd1306_set_display_start_line(0x0) &&
!ssd1306_set_charge_pump_enabled(true) &&
!ssd1306_set_mem_addr_mode(SSD1306_ADDR_MODE_HORIZ) &&
!ssd1306_set_segment_remapping_enabled(false) &&
!ssd1306_set_scan_direction_fwd(true) &&
!ssd1306_set_com_pin_hw_config(SSD1306_ALT_COM_PINS_CFG) &&
!ssd1306_set_contrast(0x9f) &&
!ssd1306_set_precharge_period(0xf1) &&
!ssd1306_set_deseltct_lvl(0x40) &&
!ssd1306_set_whole_display_lighting(true) &&
!ssd1306_set_inversion(false) &&
!ssd1306_display_on(true)) {
return 0;
}
return -EIO;
}
/*
* frame buffer of SSD1306 consists of 8 pages of 128 bits each
*
*/
int ssd1306_load_frame_buffer(uint8_t buf[], uint16_t len)
{
uint16_t i;
uint8_t j;
ssd1306_set_column_addr(0, 127);
ssd1306_set_page_addr(0, 7);
for (i=0; i<len; i++) {
i2c_start();
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(0x40)) {
debug("Error while xmitting transmission type\n");
i2c_stop();
return -EIO;
}
for (j=0;j<16;j++) {
if (!i2c_write(buf[i])) {
debug("Error while writing to GDDRAM\n");
i2c_stop();
return -EIO;
}
i++;
}
i--;
i2c_stop();
taskYIELD();
}
return 0;
}
int ssd1306_clear_screen()
{
uint16_t i = 0;
uint8_t j = 0;
ssd1306_set_column_addr(0, 127);
ssd1306_set_page_addr(0, 7);
while (i < (SSD1306_ROWS*SSD1306_COLS/8)) {
i2c_start();
if (!i2c_write(SSD1306_I2C_ADDR << 1)) {
debug("Error while xmitting I2C slave address\n");
i2c_stop();
return -EIO;
}
if (!i2c_write(0x40)) {
debug("Error while xmitting transmission type\n");
i2c_stop();
return -EIO;
}
/* write 16 bytes of data and then give resources to another task */
while (j < 16) {
if (!i2c_write(0x0)) {
debug("Error while writing to GDDRAM\n");
i2c_stop();
return -EIO;
}
i++;
j++;
}
i--;
j = 0;
i2c_stop();
taskYIELD();
}
return 0;
}
int ssd1306_display_on(bool on)
{
if (on)
return ssd1306_command(SSD1306_SET_DISPLAY_ON);
return ssd1306_command(SSD1306_SET_DISPLAY_OFF);
}
int ssd1306_set_display_start_line(uint8_t start)
{
return ssd1306_command(SSD1306_SET_DISP_START_LINE | start);
}
int ssd1306_set_display_offset(uint8_t offset)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_DISPLAY_OFFSET)))
return err;
return ssd1306_command(offset);
}
int ssd1306_set_charge_pump_enabled(bool enabled)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_CHARGE_PUMP)))
return err;
if (enabled)
return ssd1306_command(SSD1306_CHARGE_PUMP_EN);
return ssd1306_command(SSD1306_CHARGE_PUMP_DIS);
}
int ssd1306_set_mem_addr_mode(uint8_t mode)
{
if (mode >= 0x3)
return -EINVAL;
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_MEM_ADDR_MODE)))
return err;
return ssd1306_command(mode);
}
int ssd1306_set_segment_remapping_enabled(bool on)
{
if (on)
return ssd1306_command(SSD1306_SET_SEGMENT_REMAP1);
return ssd1306_command(SSD1306_SET_SEGMENT_REMAP0);
}
int ssd1306_set_scan_direction_fwd(bool fwd)
{
if (fwd)
return ssd1306_command(SSD1306_SET_SCAN_DIR_FWD);
return ssd1306_command(SSD1306_SET_SCAN_DIR_BWD);
}
int ssd1306_set_com_pin_hw_config(uint8_t config)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_COM_PINS_HW_CFG)))
return err;
return ssd1306_command(config & SSD1306_COM_PINS_HW_CFG_MASK);
}
int ssd1306_set_contrast(uint8_t contrast)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_CONTRAST)))
return err;
return ssd1306_command(contrast);
}
int ssd1306_set_inversion(bool on)
{
if (on)
return ssd1306_command(SSD1306_SET_INVERSION_ON);
return ssd1306_command(SSD1306_SET_INVERSION_OFF);
}
int ssd1306_set_osc_freq(uint8_t osc_freq)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_OSC_FREQ)))
return err;
return ssd1306_command(osc_freq);
}
int ssd1306_set_mux_ratio(uint8_t ratio)
{
if (ratio < 15)
return -EINVAL;
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_MUX_RATIO)))
return err;
return ssd1306_command(ratio);
}
int ssd1306_set_column_addr(uint8_t start, uint8_t stop)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_COL_ADDR)))
return err;
if ((err = ssd1306_command(start)))
return err;
return ssd1306_command(stop);
}
int ssd1306_set_page_addr(uint8_t start, uint8_t stop)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_PAGE_ADDR)))
return err;
if ((err = ssd1306_command(start)))
return err;
return ssd1306_command(stop);
}
int ssd1306_set_precharge_period(uint8_t prchrg)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_PRE_CHRG_PER)))
return err;
return ssd1306_command(prchrg);
}
int ssd1306_set_deseltct_lvl(uint8_t lvl)
{
int err = 0;
if ((err = ssd1306_command(SSD1306_SET_DESEL_LVL)))
return err;
return ssd1306_command(lvl);
}
int ssd1306_set_whole_display_lighting(bool light)
{
if (light)
return ssd1306_command(SSD1306_SET_ENTIRE_DISP_ON);
return ssd1306_command(SSD1306_SET_ENTIRE_DISP_OFF);
}
/* one byte of xbm - 8 dots in line of picture source
* one byte of fb - 8 rows for 1 column of screen
*/
int ssd1306_load_xbm(uint8_t *xbm, uint8_t *fb)
{
uint8_t bit = 0;
int row = 0;
int column = 0;
for (row = 0; row < SSD1306_ROWS; row ++) {
for (column = 0; column < SSD1306_COLS/8; column++) {
uint16_t xbm_offset = row * 16 + column;
for (bit = 0; bit < 8; bit++) {
if (*(xbm + xbm_offset) & 1 << bit) {
*(fb + SSD1306_COLS*(row/8)+column*8+bit) |= 1 << row%8;
}
}
}
}
return ssd1306_load_frame_buffer(fb, SSD1306_ROWS*SSD1306_COLS/8);
}

50
extras/ssd1306/ssd1306.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef _SSD1306__H_
#define _SSD1306__H_
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
// shifted
#define SSD1306_I2C_ADDR (0x3C)
#define SSD1306_ROWS (64)
#define SSD1306_COLS (128)
/* Issue single command on SSD1306 */
int ssd1306_command(uint8_t cmd);
/* Default init for SSD1306 */
int ssd1306_init();
/* Load picture in xbm format into SSD1306 RAM
* xbm - pointer to xbm picture array
* fb - pointer fo local buffer for storing converted xbm image
*/
int ssd1306_load_xbm(uint8_t *xbm, uint8_t *fb);
/* Load local framebuffer into SSD1306 RAM */
int ssd1306_load_frame_buffer(uint8_t buf[], uint16_t len);
/* Clears SSD1306 ram */
int ssd1306_clear_screen();
int ssd1306_display_on(bool on);
int ssd1306_set_display_start_line(uint8_t start);
int ssd1306_set_display_offset(uint8_t offset);
int ssd1306_set_charge_pump_enabled(bool enabled);
int ssd1306_set_mem_addr_mode(uint8_t mode);
int ssd1306_set_segment_remapping_enabled(bool on);
int ssd1306_set_scan_direction_fwd(bool fwd);
int ssd1306_set_com_pin_hw_config(uint8_t config);
int ssd1306_set_contrast(uint8_t contrast);
int ssd1306_set_inversion(bool on);
int ssd1306_set_osc_freq(uint8_t osc_freq);
int ssd1306_set_mux_ratio(uint8_t ratio);
int ssd1306_set_column_addr(uint8_t start, uint8_t stop);
int ssd1306_set_page_addr(uint8_t start, uint8_t stop);
int ssd1306_set_precharge_period(uint8_t prchrg);
int ssd1306_set_deseltct_lvl(uint8_t lvl);
int ssd1306_set_whole_display_lighting(bool light);
#endif // _SSD1306__H_

View file

@ -4,10 +4,12 @@
# for 'usage' as this module is a drop-in replacement for the original polled
# version of reading from the UART.
INC_DIRS += $(ROOT)extras/stdin_uart_interrupt
INC_DIRS += $(stdin_uart_interrupt_ROOT)
# args for passing into compile rule generation
extras/stdin_uart_interrupt_INC_DIR = $(ROOT)extras/stdin_uart_interrupt
extras/stdin_uart_interrupt_SRC_DIR = $(ROOT)extras/stdin_uart_interrupt
stdin_uart_interrupt_SRC_DIR = $(stdin_uart_interrupt_ROOT)
$(eval $(call component_compile_rules,extras/stdin_uart_interrupt))
INCLUDE_SRC_IN_AR = 0
EXTRA_LDFLAGS = -Wl,--whole-archive $(stdin_uart_interrupt_AR) -Wl,--no-whole-archive
$(eval $(call component_compile_rules,stdin_uart_interrupt))

View file

@ -40,7 +40,7 @@
#define UART0_RX_SIZE (128) // ESP8266 UART HW FIFO size
static xSemaphoreHandle uart0_sem = NULL;
static SemaphoreHandle_t uart0_sem = NULL;
static bool inited = false;
static void uart0_rx_init(void);
@ -75,9 +75,9 @@ uint32_t uart0_num_char(void)
return count;
}
// _read_r in core/newlib_syscalls.c will be skipped by the linker in favour
// _read_stdin_r in core/newlib_syscalls.c will be skipped by the linker in favour
// of this function
long _read_r(struct _reent *r, int fd, char *ptr, int len)
long _read_stdin_r(struct _reent *r, int fd, char *ptr, int len)
{
if (!inited) uart0_rx_init();
for(int i = 0; i < len; i++) {

View file

@ -195,13 +195,13 @@ static void get_channel_data(tsl2561_t *device, uint16_t *channel0, uint16_t *ch
switch (device->integration_time)
{
case TSL2561_INTEGRATION_13MS:
vTaskDelay(TSL2561_INTEGRATION_TIME_13MS / portTICK_RATE_MS);
vTaskDelay(TSL2561_INTEGRATION_TIME_13MS / portTICK_PERIOD_MS);
break;
case TSL2561_INTEGRATION_101MS:
vTaskDelay(TSL2561_INTEGRATION_TIME_101MS / portTICK_RATE_MS);
vTaskDelay(TSL2561_INTEGRATION_TIME_101MS / portTICK_PERIOD_MS);
break;
default:
vTaskDelay(TSL2561_INTEGRATION_TIME_402MS / portTICK_RATE_MS);
vTaskDelay(TSL2561_INTEGRATION_TIME_402MS / portTICK_PERIOD_MS);
break;
}

View file

@ -28,7 +28,7 @@ typedef void ETSTimerFunc(void *);
typedef struct ETSTimer_st {
struct ETSTimer_st *timer_next;
xTimerHandle timer_handle;
TimerHandle_t timer_handle;
uint32_t _unknown;
uint32_t timer_ms;
ETSTimerFunc *timer_func;

View file

@ -39,14 +39,14 @@
/* MBOX primitives */
#define SYS_MBOX_NULL ( ( xQueueHandle ) NULL )
#define SYS_SEM_NULL ( ( xSemaphoreHandle ) NULL )
#define SYS_MBOX_NULL ( ( QueueHandle_t ) NULL )
#define SYS_SEM_NULL ( ( SemaphoreHandle_t ) NULL )
#define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE
typedef xSemaphoreHandle sys_sem_t;
typedef xSemaphoreHandle sys_mutex_t;
typedef xQueueHandle sys_mbox_t;
typedef xTaskHandle sys_thread_t;
typedef SemaphoreHandle_t sys_sem_t;
typedef SemaphoreHandle_t sys_mutex_t;
typedef QueueHandle_t sys_mbox_t;
typedef TaskHandle_t sys_thread_t;
#define sys_mbox_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
#define sys_mbox_set_invalid( x ) ( ( *x ) = NULL )

View file

@ -159,7 +159,7 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
}
else
{
xReturn = xQueueSend( *pxMailBox, &pxMessageToPost, ( portTickType ) 0 );
xReturn = xQueueSend( *pxMailBox, &pxMessageToPost, ( TickType_t ) 0 );
}
if( xReturn == pdPASS )
@ -204,7 +204,7 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
u32_t sys_arch_mbox_fetch( sys_mbox_t *pxMailBox, void **ppvBuffer, u32_t ulTimeOut )
{
void *pvDummy;
portTickType xStartTime, xEndTime, xElapsed;
TickType_t xStartTime, xEndTime, xElapsed;
unsigned long ulReturn;
xStartTime = xTaskGetTickCount();
@ -218,10 +218,10 @@ unsigned long ulReturn;
{
configASSERT( is_inside_isr() == ( portBASE_TYPE ) 0 );
if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut/ portTICK_RATE_MS ) )
if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut/ portTICK_PERIOD_MS ) )
{
xEndTime = xTaskGetTickCount();
xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;
xElapsed = ( xEndTime - xStartTime ) * portTICK_PERIOD_MS;
ulReturn = xElapsed;
}
@ -236,7 +236,7 @@ unsigned long ulReturn;
{
while( pdTRUE != xQueueReceive( *pxMailBox, &( *ppvBuffer ), portMAX_DELAY ) );
xEndTime = xTaskGetTickCount();
xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;
xElapsed = ( xEndTime - xStartTime ) * portTICK_PERIOD_MS;
if( xElapsed == 0UL )
{
@ -358,17 +358,17 @@ err_t xReturn = ERR_MEM;
*---------------------------------------------------------------------------*/
u32_t sys_arch_sem_wait( sys_sem_t *pxSemaphore, u32_t ulTimeout )
{
portTickType xStartTime, xEndTime, xElapsed;
TickType_t xStartTime, xEndTime, xElapsed;
unsigned long ulReturn;
xStartTime = xTaskGetTickCount();
if( ulTimeout != 0UL )
{
if( xSemaphoreTake( *pxSemaphore, ulTimeout / portTICK_RATE_MS ) == pdTRUE )
if( xSemaphoreTake( *pxSemaphore, ulTimeout / portTICK_PERIOD_MS ) == pdTRUE )
{
xEndTime = xTaskGetTickCount();
xElapsed = (xEndTime - xStartTime) * portTICK_RATE_MS;
xElapsed = (xEndTime - xStartTime) * portTICK_PERIOD_MS;
ulReturn = xElapsed;
}
else
@ -380,7 +380,7 @@ unsigned long ulReturn;
{
while( xSemaphoreTake( *pxSemaphore, portMAX_DELAY ) != pdTRUE );
xEndTime = xTaskGetTickCount();
xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;
xElapsed = ( xEndTime - xStartTime ) * portTICK_PERIOD_MS;
if( xElapsed == 0UL )
{
@ -487,7 +487,7 @@ void sys_init(void)
u32_t sys_now(void)
{
return xTaskGetTickCount() * portTICK_RATE_MS;
return xTaskGetTickCount() * portTICK_PERIOD_MS;
}
/*---------------------------------------------------------------------------*
@ -510,7 +510,7 @@ u32_t sys_now(void)
*---------------------------------------------------------------------------*/
sys_thread_t sys_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority )
{
xTaskHandle xCreatedTask;
TaskHandle_t xCreatedTask;
portBASE_TYPE xResult;
sys_thread_t xReturn;

View file

@ -72,7 +72,7 @@ void IRAM sdk__xt_int_exit(void) {
void IRAM sdk__xt_timer_int(void) {
uint32_t trigger_ccount;
uint32_t current_ccount;
uint32_t ccount_interval = portTICK_RATE_MS * sdk_os_get_cpu_frequency() * 1000;
uint32_t ccount_interval = portTICK_PERIOD_MS * sdk_os_get_cpu_frequency() * 1000;
do {
RSR(trigger_ccount, ccompare0);
@ -93,7 +93,7 @@ void IRAM sdk__xt_timer_int1(void) {
void IRAM sdk__xt_tick_timer_init(void) {
uint32_t ints_enabled;
uint32_t current_ccount;
uint32_t ccount_interval = portTICK_RATE_MS * sdk_os_get_cpu_frequency() * 1000;
uint32_t ccount_interval = portTICK_PERIOD_MS * sdk_os_get_cpu_frequency() * 1000;
RSR(current_ccount, ccount);
WSR(current_ccount + ccount_interval, ccompare0);

View file

@ -60,7 +60,7 @@ void sdk_os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg) {
*tailptr = new_entry;
}
static void timer_tramp(xTimerHandle xTimer)
static void timer_tramp(TimerHandle_t xTimer)
{
ETSTimer *ptimer = pvTimerGetTimerID(xTimer);
ptimer->timer_func(ptimer->timer_arg);

View file

@ -42,8 +42,8 @@ PRINTF_SCANF_FLOAT_SUPPORT ?= 1
FLAVOR ?= release # or debug
# Include source files into static library
INCLUDE_SRC_INTO_AR ?= 1
# Include source files into a static library. It improves error messages.
INCLUDE_SRC_IN_AR ?= 1
# Compiler names, etc. assume gdb
CROSS ?= xtensa-lx106-elf-

View file

@ -19,7 +19,7 @@ TESTCASE_SRC_FILES = $(wildcard $(PROGRAM_DIR)cases/*.c)
# Do not include source files into a static library because when adding this
# library with '--whole-archive' linker gives error that archive contains
# unknown objects (source files)
INCLUDE_SRC_INTO_AR = 0
INCLUDE_SRC_IN_AR = 0
# Link every object in the 'program' archive, to pick up constructor functions for test cases
EXTRA_LDFLAGS = -Wl,--whole-archive $(BUILD_DIR)program.a -Wl,--no-whole-archive

View file

@ -46,7 +46,7 @@ static void a_01_scheduler_priorities()
vTaskPrioritySet(xTaskGetCurrentTaskHandle(), tskIDLE_PRIORITY+4);
bool lower = false, higher = false;
xTaskHandle task_lower, task_higher;
TaskHandle_t task_lower, task_higher;
xTaskCreate(set_variable, "high_prio", 128, (void *)&higher, tskIDLE_PRIORITY+1, &task_higher);
xTaskCreate(set_variable, "low_prio", 128, (void *)&lower, tskIDLE_PRIORITY, &task_lower);

View file

@ -68,7 +68,7 @@ static void server_task(void *pvParameters)
buf[pb->len] = 0;
break;
}
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
TEST_ASSERT_TRUE_MESSAGE(pb->len > 0, "No data received");
printf("Device A: received data: %s\n", buf);
@ -122,7 +122,7 @@ static void connect_task(void *pvParameters)
// wait for wifi connection
while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) {
vTaskDelay(1000 / portTICK_RATE_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("Waiting for connection to AP\n");
}
@ -148,7 +148,7 @@ static void connect_task(void *pvParameters)
if (r > 0) {
break;
}
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
TEST_ASSERT_TRUE_MESSAGE(r > 0, "No data received");

View file

@ -69,7 +69,7 @@ static void test_task(void *pvParameters)
timers[1].start_time = get_current_time();
sdk_ets_timer_arm(&timers[1].handle, 50, true); // repeating timer
vTaskDelay(500 / portTICK_RATE_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
TEST_ASSERT_EQUAL_INT_MESSAGE(1, timers[0].fire_count,
"Timer hasn't fired");