Skip to content

Commit

Permalink
Merge branch 'feature/8266_support' into 'master'
Browse files Browse the repository at this point in the history
ESP8266 support

See merge request app-frameworks/esp-homekit-sdk!2
  • Loading branch information
shahpiyushv committed Oct 8, 2020
2 parents cc01b2f + 9494cc1 commit f2a010a
Show file tree
Hide file tree
Showing 34 changed files with 91 additions and 627 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
## Introduction

[HomeKit](https://developer.apple.com/homekit/) is a framework developed by Apple for communicating with and controlling connected accessories in a user’s home using iOS devices.
ESP HomeKit SDK has been developed in-house by Espressif to build Apple HomeKit compatible accessories using ESP32/ESP32-S2 SoCs.
ESP HomeKit SDK has been developed in-house by Espressif to build Apple HomeKit compatible accessories using ESP32/ESP32-S2/ESP8266 SoCs.

> Note: If you want to use HomeKit for commercial products, please check [here](https://www.espressif.com/en/products/sdks/esp-homekit-sdk) for access to the MFi variant of this SDK. It has the exact same APIs as this and so, moving to it should be easy.
> Note: If you want to use HomeKit for commercial products, please check [here](https://www.espressif.com/en/products/sdks/esp-homekit-sdk) for access to the MFi variant of this SDK. It has the exact same APIs as this and so, moving to it should be easy. However, commercial HomeKit products can be built only with ESP32/ESP32-S2 since ESP8266 cannot meet all the HomeKit Certification requirements.
> If you want to use a port of Apple's ADK instead, please check [here](https://github.com/espressif/esp-apple-homekit-adk)
Expand All @@ -21,6 +21,8 @@ Features of this SDK:

Set up the host environment and ESP IDF (**master** branch) as per the steps given [here](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html).

If you are using **ESP8266**, set-up ESP8266-RTOS-SDK (**master** branch) as per the steps given [here](https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/).

### Get esp-homekit-sdk

Please clone this repository using the below command:
Expand All @@ -35,7 +37,9 @@ git clone --recursive https://github.com/espressif/esp-homekit-sdk.git

### Compile and Flash

You can use esp-homekit-sdk with any ESP32 or ESP32-S2 board. We have provided multiple examples for reference. Compile and flash as below (fan used as example):
You can use esp-homekit-sdk with any ESP32, ESP32-S2 or ESP8266 board (though we have tested only with the ESP32-DevKit-C, ESP32-S2-Saola-1 and ESP8266-DevKit-C). We have provided multiple examples for reference. Compile and flash as below (fan used as example):

**For ESP32/ESP32-S2**

```text
$ cd /path/to/esp-homekit-sdk/examples/fan
Expand All @@ -44,6 +48,16 @@ $ idf.py set-target <esp32/esp32s2>
$ idf.py flash monitor
```

**For ESP8266**

```text
$ cd /path/to/esp-homekit-sdk/examples/fan
$ export ESPPORT=/dev/tty.SLAB_USBtoUART #Set your board's serial port here
$ make defconfig
$ make flash monitor
```


As the device boots up, you will see two QR codes, a small one for HomeKit and a larger one for Wi-Fi provisioning. Please use any of the [Espressif Provisioning Apps](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/provisioning.html#provisioning-tools) for Wi-Fi provisioning.

> Note: For the Open source HomeKit SDK, the HomeKit QR code cannot be used for provisioning from the Home app. It can be used only for pairing, after the Wi-Fi provisioning is done. For provisioning from Home app, you will need the MFi variant of the SDK.
Expand All @@ -65,6 +79,8 @@ Open the Home app on your iPhone/iPad and follow these steps
- You should eventually see the "Esp-Fan-xxxxxx added" message.
- Give a custom name, assign to a room, create scenes as required and you are done.

> For ESP8266, the pairing may take a bit longer.
### Changing the Setup Code

The HomeKit setup code can be changed by using the `CONFIG_EXAMPLE_SETUP_CODE` config option (`idf.py menuconfig -> Example Configuration -> HomeKit Setup Code`). Please also refer the [HomeKit Setup Configuration](#homeKit-setup-configuration) below.
Expand Down
2 changes: 1 addition & 1 deletion components/homekit/esp_hap_core/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MFI_VER := $(HAP_SDK_VER)-$(shell git log --pretty=format:"%h" -1)

ifdef CONFIG_HAP_MFI_ENABLE
COMPONENT_SRCDIRS += src/mfi
COMPONENT_OBJEXCLUDE += src/esp_mfi_dummy.c
COMPONENT_OBJEXCLUDE += src/esp_mfi_dummy.o
COMPONENT_PRIV_INCLUDEDIRS += src/mfi
endif

Expand Down
1 change: 0 additions & 1 deletion components/homekit/esp_hap_core/src/esp_hap_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <freertos/task.h>
#include <freertos/queue.h>
#include <esp_event.h>
#include <esp_eth.h>
#include <esp_wifi.h>

#include <esp_mfi_debug.h>
Expand Down
2 changes: 1 addition & 1 deletion components/homekit/esp_hap_extras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set(COMPONENT_ADD_INCLUDEDIRS include)

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES esp_hap_core)
set(COMPONENT_PRIV_REQUIRES esp_http_server esp_https_ota protocomm wifi_provisioning bt esp_hap_platform app_update)
set(COMPONENT_PRIV_REQUIRES esp_http_server esp_https_ota esp_hap_platform app_update)

set(COMPONENT_SRCS src/hap_bct_http_handlers.c src/hap_fw_upgrade.c)

Expand Down
16 changes: 8 additions & 8 deletions components/homekit/esp_hap_platform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
set(COMPONENT_ADD_INCLUDEDIRS include)
set(srcs src/esp_mfi_aes.c src/esp_mfi_base64.c src/esp_mfi_rand.c src/esp_mfi_sha.c src/hap_platform_httpd.c src/hap_platform_keystore.c src/hap_platform_memory.c src/hap_platform_os.c)

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES esp_http_server)
set(COMPONENT_PRIV_REQUIRES mbedtls nvs_flash mdns esp_eth esp_hap_core)

set(COMPONENT_SRCS src/esp32/esp_mfi_aes.c src/esp32/esp_mfi_base64.c src/esp32/esp_mfi_i2c.c src/esp32/esp_mfi_rand.c src/esp32/esp_mfi_sha.c src/esp32/hap_platform_httpd.c src/esp32/hap_platform_keystore.c src/esp32/hap_platform_memory.c src/esp32/hap_platform_os.c)

register_component()
if(NOT CONFIG_IDF_TARGET_ESP8266)
list(APPEND srcs src/esp_mfi_i2c.c)
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS "include"
REQUIRES esp_http_server
PRIV_REQUIRES mbedtls nvs_flash mdns esp_hap_core)
component_compile_options(-Wno-unused-function)
2 changes: 2 additions & 0 deletions components/homekit/esp_hap_platform/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ menu "MFi I2C Setup"
int "SDA GPIO"
default 26 if IDF_TARGET_ESP32
default 4 if IDF_TARGET_ESP32S2
default 2 if IDF_TARGET_ESP8266
help
GPIO for SDA - please check schematic carefully

config SCL_GPIO
int "SCL GPIO"
default 27 if IDF_TARGET_ESP32
default 5 if IDF_TARGET_ESP32S2
default 14 if IDF_TARGET_ESP8266
help
GPIO for SCL - please check schematic carefully

Expand Down
5 changes: 4 additions & 1 deletion components/homekit/esp_hap_platform/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
# Component Makefile
#
CFLAGS += -Wno-unused-function
COMPONENT_SRCDIRS := src/esp32
COMPONENT_SRCDIRS := src
ifdef CONFIG_IDF_TARGET_ESP8266
COMPONENT_OBJEXCLUDE += src/esp_mfi_i2c.o
endif
COMPONENT_ADD_INCLUDEDIRS := include
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

#include "esp_mfi_sha.h"

#ifdef CONFIG_IDF_TARGET_ESP8266
#define mbedtls_sha512_starts mbedtls_sha512_starts_ret
#define mbedtls_sha512_update mbedtls_sha512_update_ret
#define mbedtls_sha512_finish mbedtls_sha512_finish_ret
#endif

/**
* @bref Create SHA1 context
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ esp_err_t hap_platform_httpd_set_sess_ctx(httpd_req_t *req, void *ctx, httpd_fre
if (req) {
req->sess_ctx = ctx;
req->free_ctx = free_ctx;
#ifndef CONFIG_IDF_TARGET_ESP8266
req->ignore_sess_ctx_changes = ignore_ctx_changes;
#endif
return ESP_OK;
}
return ESP_FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
*/
#include <stdint.h>
#include <freertos/FreeRTOS.h>
#include <freertos/FreeRTOSConfig.h>
#include <freertos/portmacro.h>

Expand Down
31 changes: 31 additions & 0 deletions components/homekit/mu_srp/mu_bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ static inline int mu_bn_a_add_b_mod_c(mu_bn_t *result, mu_bn_t *a, mu_bn_t *b, m
#ifdef BIGNUM_MBEDTLS
#include <mbedtls/bignum.h>
#include <esp_system.h>
#ifdef CONFIG_IDF_TARGET_ESP8266
#include <driver/rtc.h>
#endif
typedef mbedtls_mpi mu_bn_t;
typedef mu_bn_t mu_bn_ctx_t;

Expand Down Expand Up @@ -166,6 +169,27 @@ static inline int mu_bn_get_rand(mu_bn_t *bn, int bits, int top, int bottom)
return mbedtls_mpi_fill_random(bn, bits / 8, mu_get_random, NULL);
}

#ifdef CONFIG_IDF_TARGET_ESP8266
static inline int mu_bn_a_exp_b_mod_c(mu_bn_t *result, mu_bn_t *a, mu_bn_t *b, mu_bn_t *c, mu_bn_ctx_t *ctx)
{
int ret;
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_160M);
ret = mbedtls_mpi_exp_mod(result, a, b, c, (mu_bn_t *) ctx);
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M);
return ret;
}
static inline int mu_bn_a_mul_b_mod_c(mu_bn_t *result, mu_bn_t *a, mu_bn_t *b, mu_bn_t *c, mu_bn_ctx_t *ctx)
{
mbedtls_mpi tmp_result;
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_160M);
mbedtls_mpi_init(&tmp_result);
mbedtls_mpi_mul_mpi(&tmp_result, a, b);
mbedtls_mpi_mod_mpi(result, &tmp_result, c);
mbedtls_mpi_free(&tmp_result);
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M);
return 0;
}
#else
static inline int mu_bn_a_exp_b_mod_c(mu_bn_t *result, mu_bn_t *a, mu_bn_t *b, mu_bn_t *c, mu_bn_ctx_t *ctx)
{
return mbedtls_mpi_exp_mod(result, a, b, c, (mu_bn_t *) ctx);
Expand All @@ -175,17 +199,24 @@ static inline int mu_bn_a_mul_b_mod_c(mu_bn_t *result, mu_bn_t *a, mu_bn_t *b, m
{
return esp_mpi_mul_mpi_mod(result, a, b, c);
}
#endif /* !CONFIG_IDF_TARGET_ESP8266 */

static inline int mu_bn_a_add_b_mod_c(mu_bn_t *result, mu_bn_t *a, mu_bn_t *b, mu_bn_t *c, mu_bn_ctx_t *ctx)
{
int res;
mbedtls_mpi t;
#ifdef CONFIG_IDF_TARGET_ESP8266
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_160M);
#endif
mbedtls_mpi_init(&t);
res = mbedtls_mpi_add_mpi(&t, a, b);
if (res == 0) {
res = mbedtls_mpi_mod_mpi(result, &t, c);
}
mbedtls_mpi_free(&t);
#ifdef CONFIG_IDF_TARGET_ESP8266
rtc_clk_cpu_freq_set(RTC_CPU_FREQ_80M);
#endif
return res;
}
#endif /* BIGNUM_MBEDTLS */
Expand Down
9 changes: 0 additions & 9 deletions components/led/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit f2a010a

Please sign in to comment.