Skip to content

Commit

Permalink
Add OTAR to all-clusters-app and lighting-app
Browse files Browse the repository at this point in the history
  • Loading branch information
pankore committed Jan 19, 2022
1 parent c7eb588 commit 4365506
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 129 deletions.
18 changes: 18 additions & 0 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ list(
)
endif (matter_enable_rpc)

if (matter_enable_otar)
list(
APPEND ${list_chip_main_sources}
#otar
${chip_dir}/src/app/clusters/ota-requestor/BDXDownloader.cpp
${chip_dir}/src/app/clusters/ota-requestor/OTARequestor.cpp
${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
)
endif (matter_enable_otar)

list(
APPEND ${list_chip_main_sources}

Expand Down Expand Up @@ -229,6 +239,14 @@ list(
)
endif (matter_enable_rpc)

if (matter_enable_otar)
list(
APPEND chip_main_flags

-DCONFIG_ENABLE_OTAR=1
)
endif (matter_enable_otar)

list(
APPEND chip_main_cpp_flags

Expand Down
75 changes: 73 additions & 2 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <support/CHIPMem.h>

#if CONFIG_ENABLE_OTAR
#include "platform/Ameba/AmebaOTAImageProcessor.h"
#include "platform/GenericOTARequestorDriver.h"
#include "app/clusters/ota-requestor/BDXDownloader.h"
#include "app/clusters/ota-requestor/OTARequestor.h"
#endif

#if CONFIG_ENABLE_PW_RPC
#include "Rpc.h"
#endif
Expand All @@ -44,6 +51,7 @@ using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;

Identify gIdentify0 = {
chip::EndpointId{ 0 },
Expand Down Expand Up @@ -72,6 +80,13 @@ Identify gIdentify1 = {

static DeviceCallbacks EchoCallbacks;

#if CONFIG_ENABLE_OTAR
OTARequestor gRequestorCore;
GenericOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
AmebaOTAImageProcessor gImageProcessor;
#endif

void GetGatewayIP(char * ip_buf, size_t ip_len)
{
uint8_t * gateway = LwIP_GetGW(&xnetif[0]);
Expand Down Expand Up @@ -185,6 +200,61 @@ std::string createSetupPayload()
return result;
};

#if CONFIG_ENABLE_OTAR
void QueryImageTimerHandler(Layer * systemLayer, void * appState)
{
ChipLogProgress(DeviceLayer, "QueryImageTimerHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
}

void ApplyUpdateTimerHandler(Layer * systemLayer, void * appState)
{
ChipLogProgress(DeviceLayer, "ApplyUpdateTimerHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
}

extern "C" void amebaQueryImageCmdHandler(uint32_t nodeId, uint32_t fabricId)
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
// In this mode Provider node ID and fabric idx must be supplied explicitly from ATS$ cmd
gRequestorCore.TestModeSetProviderParameters(nodeId, fabricId, chip::kRootEndpointId);

/* Start one shot timer with 1 second timeout to send QueryImage Request command */
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(1 * 1000), QueryImageTimerHandler, nullptr);
}

extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");

/* Start one shot timer with 1 second timeout to send QueryImage Request command */
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(1 * 1000), ApplyUpdateTimerHandler, nullptr);
}

static void InitOTARequestor(void)
{
// Initialize and interconnect the Requestor and Image Processor objects -- START
SetRequestorInstance(&gRequestorCore);

// Set server instance used for session establishment
gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader);

// WARNING: this is probably not realistic to know such details of the image or to even have an OTADownloader instantiated at
// the beginning of program execution. We're using hardcoded values here for now since this is a reference application.
// TODO: instatiate and initialize these values when QueryImageResponse tells us an image is available
// TODO: add API for OTARequestor to pass QueryImageResponse info to the application to use for OTADownloader init
OTAImageProcessorParams ipParams;
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gImageProcessor.SetOTADownloader(&gDownloader);

// Connect the Downloader and Image Processor objects
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);

// Initialize and interconnect the Requestor and Image Processor objects -- END
}
#endif // CONFIG_ENABLE_OTAR

extern "C" void ChipTest(void)
{
ChipLogProgress(DeviceLayer, "All Clusters Demo!");
Expand Down Expand Up @@ -229,8 +299,9 @@ extern "C" void ChipTest(void)

statusLED1.Init(STATUS_LED_GPIO_NUM);

while (true)
vTaskDelay(pdMS_TO_TICKS(50));
#if CONFIG_ENABLE_OTAR
InitOTARequestor();
#endif
}

bool lowPowerClusterSleep()
Expand Down
125 changes: 1 addition & 124 deletions examples/all-clusters-app/ameba/main/include/LEDWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,132 +21,9 @@
#include <platform_stdlib.h>

#ifdef CONFIG_PLATFORM_8710C
#include "gpio_api.h"
#include "rtl8710c_pin_name.h"

typedef struct hal_gpio_pin_adapter_s
{
uint8_t pin_name; ///< chip pin name to locate the GPIO pin by port & pin index
uint8_t port_idx; ///< the GPIO IP port index of the GPIO pin
uint8_t pin_idx; ///< the GPIO IP pin index of the GPIO port
uint8_t debounce_idx; ///< the index of GPIO debounce function allocated to this GPIO pin, 0 ~ 15
uint32_t bit_mask; ///< the bit mask to read/write register

volatile uint32_t * in_port; ///< the IN port address
volatile uint32_t * out0_port; ///< the OUT port address for write 0
volatile uint32_t * out1_port; ///< the OUT port address for write 1
volatile uint32_t * outt_port; ///< the OUT port address for toggling
} hal_gpio_adapter_t, *phal_gpio_adapter_t;

typedef enum
{
PIN_INPUT = 0,
PIN_OUTPUT
} PinDirection;

typedef enum
{
PA_0 = PIN_A0,
PA_1 = PIN_A1,
PA_2 = PIN_A2,
PA_3 = PIN_A3,
PA_4 = PIN_A4,
PA_5 = PIN_A5,
PA_6 = PIN_A6,
PA_7 = PIN_A7,
PA_8 = PIN_A8,
PA_9 = PIN_A9,
PA_10 = PIN_A10,
PA_11 = PIN_A11,
PA_12 = PIN_A12,
PA_13 = PIN_A13,
PA_14 = PIN_A14,
PA_15 = PIN_A15,
PA_16 = PIN_A16,
PA_17 = PIN_A17,
PA_18 = PIN_A18,
PA_19 = PIN_A19,
PA_20 = PIN_A20,
PA_21 = PIN_A21,
PA_22 = PIN_A22,
PA_23 = PIN_A23,

PB_0 = PIN_B0,
PB_1 = PIN_B1,
PB_2 = PIN_B2,
PB_3 = PIN_B3,
PB_4 = PIN_B4,
PB_5 = PIN_B5,
PB_6 = PIN_B6,
PB_7 = PIN_B7,
PB_8 = PIN_B8,
PB_9 = PIN_B9,
PB_10 = PIN_B10,
PB_11 = PIN_B11,
PB_12 = PIN_B12,

// Arduino connector namings
/*
A0 = PA_0,
A1 = PA_1,
A2 = PA_4,
A3 = PB_0,
A4 = PC_1,
A5 = PC_0,
D0 = PA_3,
D1 = PA_2,
D2 = PA_10,
D3 = PB_3,
D4 = PB_5,
D5 = PB_4,
D6 = PB_10,
D7 = PA_8,
D8 = PA_9,
D9 = PC_7,
D10 = PB_6,
D11 = PA_7,
D12 = PA_6,
D13 = PA_5,
D14 = PB_9,
D15 = PB_8,
*/

// Generic signals namings
/*
LED1 = PB_4,
LED2 = PB_5,
LED3 = PB_6,
LED4 = PB_7,
USER_BUTTON = PA_3,
SERIAL_TX = PA_7,
SERIAL_RX = PA_6,
USBTX = PA_7,
USBRX = PA_6,
I2C_SCL = PC_5,
I2C_SDA = PC_4,
SPI_MOSI = PC_2,
SPI_MISO = PC_3,
SPI_SCK = PC_1,
SPI_CS = PC_0,
PWM_OUT = PD_4,
*/
// Not connected
NC = (uint32_t) 0xFFFFFFFF
} PinName;

typedef enum
{
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrain = 3,
PullDefault = PullNone
} PinMode;

struct gpio_s
{
hal_gpio_adapter_t adapter;
};

#else

typedef enum
Expand Down
18 changes: 18 additions & 0 deletions examples/lighting-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ set(list_chip_main_sources chip_main_sources)

include(${prj_root}/GCC-RELEASE/project_hp/asdk/includepath.cmake)

if (matter_enable_otar)
list(
APPEND ${list_chip_main_sources}
#otar
${chip_dir}/src/app/clusters/ota-requestor/BDXDownloader.cpp
${chip_dir}/src/app/clusters/ota-requestor/OTARequestor.cpp
${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
)
endif (matter_enable_otar)

list(
APPEND ${list_chip_main_sources}

Expand Down Expand Up @@ -73,6 +83,14 @@ list(
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
)

if (matter_enable_otar)
list(
APPEND chip_main_flags

-DCONFIG_ENABLE_OTAR=1
)
endif (matter_enable_otar)

list(
APPEND chip_main_cpp_flags

Expand Down
Loading

0 comments on commit 4365506

Please sign in to comment.