Skip to content

Commit

Permalink
Split into different platform modules, add support for ESP8266_RTOS_SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkulkin committed Jan 9, 2020
1 parent 1dac03f commit bed2c8d
Show file tree
Hide file tree
Showing 43 changed files with 230 additions and 59 deletions.
31 changes: 17 additions & 14 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
[submodule "components/cJSON"]
path = components/esp-8266/cJSON
url = https://github.com/maximkulkin/esp-cjson
[submodule "components/wolfssl"]
path = components/common/wolfssl
url = https://github.com/maximkulkin/esp-wolfssl
[submodule "components/homekit"]
path = components/common/homekit
url = https://github.com/maximkulkin/esp-homekit
[submodule "components/http-parser"]
path = components/esp-32/http-parser
[submodule "components/esp32/idf/http-parser"]
path = components/esp-idf/http-parser
url = https://github.com/maximkulkin/esp-http-parser.git
[submodule "components/wifi_config"]
path = components/esp-8266/wifi_config
url = https://github.com/maximkulkin/esp-wifi-config
[submodule "components/WS2812FX"]
path = components/esp-8266/WS2812FX
[submodule "components/esp8266-idf/http-parser"]
path = components/esp8266-rtos-sdk/http-parser
url = https://github.com/maximkulkin/esp-http-parser.git
[submodule "components/esp8266-open-rtos/WS2812FX"]
path = components/esp8266-open-rtos/WS2812FX
url = https://github.com/pcsaito/WS2812FX-rtos
[submodule "components/led-status"]
path = components/esp-8266/led-status
[submodule "components/esp8266-open-rtos/cJSON"]
path = components/esp8266-open-rtos/cJSON
url = https://github.com/maximkulkin/esp-cjson
[submodule "components/esp8266-open-rtos/led-status"]
path = components/esp8266-open-rtos/led-status
url = https://github.com/maximkulkin/esp-led-status.git
[submodule "components/esp-8266/qrcode"]
path = components/esp-8266/qrcode
[submodule "components/esp8266-open-rtos/qrcode"]
path = components/esp8266-open-rtos/qrcode
url = https://github.com/maximkulkin/esp-qrcode.git
[submodule "components/esp8266-open-rtos/wifi_config"]
path = components/esp8266-open-rtos/wifi_config
url = https://github.com/maximkulkin/esp-wifi-config
2 changes: 1 addition & 1 deletion components/common/homekit
Submodule homekit updated 1 files
+1 −1 component.mk
2 changes: 1 addition & 1 deletion components/common/wolfssl
1 change: 0 additions & 1 deletion components/esp-32/http-parser
Submodule http-parser deleted from b6f4f5
1 change: 0 additions & 1 deletion components/esp-8266/wifi_config
Submodule wifi_config deleted from fe2e98
1 change: 1 addition & 0 deletions components/esp-idf/http-parser
Submodule http-parser added at 59eec2
1 change: 1 addition & 0 deletions components/esp8266-open-rtos/wifi_config
Submodule wifi_config added at 06901b
1 change: 1 addition & 0 deletions components/esp8266-rtos-sdk/http-parser
Submodule http-parser added at 59eec2
2 changes: 1 addition & 1 deletion examples/ZemiSmart/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = light

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/accessory_names/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = accessory_names

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/blinds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = blinds

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/button/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = button

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/door-sensor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = door-sensor

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic_services/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ PROGRAM = dynamic_services
EXTRA_COMPONENTS = \
extras/http-parser \
extras/dhcpserver \
$(abspath ../../components/esp-8266/wifi_config) \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/wifi_config) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/esp32/led/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ CFLAGS += -I$(abspath ../../..) -DHOMEKIT_SHORT_APPLE_UUIDS

EXTRA_COMPONENT_DIRS += \
$(abspath ../../../components/common) \
$(abspath ../../../components/esp-32)
$(abspath ../../../components/esp32-idf)

include $(IDF_PATH)/make/project.mk
4 changes: 4 additions & 0 deletions examples/esp8266-rtos-sdk/led/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
firmware/
sdkconfig
sdkconfig.old
9 changes: 9 additions & 0 deletions examples/esp8266-rtos-sdk/led/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PROJECT_NAME = led

EXTRA_CFLAGS += -I$(abspath ../../..) -DHOMEKIT_SHORT_APPLE_UUIDS

EXTRA_COMPONENT_DIRS += \
$(abspath ../../../components/common) \
$(abspath ../../../components/esp8266-rtos-sdk)

include $(IDF_PATH)/make/project.mk
1 change: 1 addition & 0 deletions examples/esp8266-rtos-sdk/led/main/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPONENT_DEPENDS = homekit
153 changes: 153 additions & 0 deletions examples/esp8266-rtos-sdk/led/main/led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#include <stdio.h>
#include <esp_wifi.h>
#include <esp_event_loop.h>
#include <esp_log.h>
#include <nvs_flash.h>

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <driver/gpio.h>

#include <homekit/homekit.h>
#include <homekit/characteristics.h>
#include "wifi.h"


void on_wifi_ready();

esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
case SYSTEM_EVENT_STA_START:
printf("STA start\n");
esp_wifi_connect();
break;
case SYSTEM_EVENT_STA_GOT_IP:
printf("WiFI ready\n");
on_wifi_ready();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
printf("STA disconnected\n");
esp_wifi_connect();
break;
default:
break;
}
return ESP_OK;
}

static void wifi_init() {
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));

wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_config));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));

wifi_config_t wifi_config = {
.sta = {
.ssid = WIFI_SSID,
.password = WIFI_PASSWORD,
},
};

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
}

const int led_gpio = 2;
bool led_on = false;

void led_write(bool on) {
gpio_set_level(led_gpio, on ? 1 : 0);
}

void led_init() {
gpio_set_direction(led_gpio, GPIO_MODE_OUTPUT);
led_write(led_on);
}

void led_identify_task(void *_args) {
for (int i=0; i<3; i++) {
for (int j=0; j<2; j++) {
led_write(true);
vTaskDelay(100 / portTICK_PERIOD_MS);
led_write(false);
vTaskDelay(100 / portTICK_PERIOD_MS);
}

vTaskDelay(250 / portTICK_PERIOD_MS);
}

led_write(led_on);

vTaskDelete(NULL);
}

void led_identify(homekit_value_t _value) {
printf("LED identify\n");
xTaskCreate(led_identify_task, "LED identify", 512, NULL, 2, NULL);
}

homekit_value_t led_on_get() {
return HOMEKIT_BOOL(led_on);
}

void led_on_set(homekit_value_t value) {
if (value.format != homekit_format_bool) {
printf("Invalid value format: %d\n", value.format);
return;
}

led_on = value.bool_value;
led_write(led_on);
}


homekit_accessory_t *accessories[] = {
HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_lightbulb, .services=(homekit_service_t*[]){
HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]){
HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"),
HOMEKIT_CHARACTERISTIC(MANUFACTURER, "HaPK"),
HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "037A2BABF19D"),
HOMEKIT_CHARACTERISTIC(MODEL, "MyLED"),
HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "0.1"),
HOMEKIT_CHARACTERISTIC(IDENTIFY, led_identify),
NULL
}),
HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){
HOMEKIT_CHARACTERISTIC(NAME, "Sample LED"),
HOMEKIT_CHARACTERISTIC(
ON, false,
.getter=led_on_get,
.setter=led_on_set
),
NULL
}),
NULL
}),
NULL
};

homekit_server_config_t config = {
.accessories = accessories,
.password = "111-11-111"
};

void on_wifi_ready() {
homekit_server_init(&config);
}

void app_main(void) {
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );

wifi_init();
led_init();
}
2 changes: 1 addition & 1 deletion examples/fireplace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ EXTRA_COMPONENTS = \
extras/ws2812_i2s \
extras/rboot-ota \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/garage/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = garage

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
2 changes: 1 addition & 1 deletion examples/led/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROGRAM = led

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
4 changes: 2 additions & 2 deletions examples/led_status/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ PROGRAM = led_status

EXTRA_COMPONENTS = \
extras/http-parser \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit) \
$(abspath ../../components/esp-8266/led-status)
$(abspath ../../components/esp8266-open-rtos/led-status)

FLASH_SIZE ?= 32

Expand Down
2 changes: 1 addition & 1 deletion examples/led_strip/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ EXTRA_COMPONENTS = \
extras/http-parser \
extras/i2s_dma \
extras/ws2812_i2s \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
4 changes: 2 additions & 2 deletions examples/led_strip_animation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ EXTRA_COMPONENTS = \
extras/http-parser \
extras/i2s_dma \
extras/ws2812_i2s \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit) \
$(abspath ../../components/esp-8266/WS2812FX)
$(abspath ../../components/esp8266-open-rtos/WS2812FX)

FLASH_SIZE ?= 32
# FLASH_SIZE ?= 8
Expand Down
4 changes: 2 additions & 2 deletions examples/lock/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ PROGRAM = lock
EXTRA_COMPONENTS = \
extras/http-parser \
extras/dhcpserver \
$(abspath ../../components/esp-8266/wifi_config) \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/wifi_config) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
4 changes: 2 additions & 2 deletions examples/magic_home_strip/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ EXTRA_COMPONENTS = \
extras/http-parser \
extras/multipwm \
extras/dhcpserver \
$(abspath ../../components/esp-8266/wifi_config) \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/wifi_config) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit)

Expand Down
4 changes: 2 additions & 2 deletions examples/qrcode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ EXTRA_COMPONENTS = \
extras/ssd1306 \
extras/i2c \
extras/fonts \
$(abspath ../../components/esp-8266/cJSON) \
$(abspath ../../components/esp8266-open-rtos/cJSON) \
$(abspath ../../components/common/wolfssl) \
$(abspath ../../components/common/homekit) \
$(abspath ../../components/esp-8266/qrcode)
$(abspath ../../components/esp8266-open-rtos/qrcode)

# Enable fonts provided by extras/fonts package
FONTS_TERMINUS_6X12_ISO8859_1 = 1
Expand Down
Loading

0 comments on commit bed2c8d

Please sign in to comment.