Skip to content

Commit

Permalink
style(api): modify format for function names
Browse files Browse the repository at this point in the history
1. change api names, add iot_ prefix for all the c functions
2. update idf submodule
3. modify i2c device functions
4. add missing files
  • Loading branch information
costaud committed Nov 7, 2017
1 parent dcf879e commit d335224
Show file tree
Hide file tree
Showing 133 changed files with 1,322 additions and 1,327 deletions.
2 changes: 1 addition & 1 deletion components/base_class/controllable_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "controllable_obj.h"
#include "iot_controllable_obj.h"

CControllable::~CControllable() {};
4 changes: 2 additions & 2 deletions components/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
This components are based on GPIO provided by idf and soft timer provided by FreeRTOS.

* To use the button device, you need to :
* create a button object returned by button_create().
* create a button object returned by iot_button_create().
* Then hook different event callbacks to the button object.
* To free the object, you can call button_delete to delete the button object and free the memory that used.
* To free the object, you can call iot_button_delete to delete the button object and free the memory that used.

* Todo:
* Add hardware timer mode(because sometimes soft-timer callback function is limited)
Expand Down
12 changes: 6 additions & 6 deletions components/button/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "freertos/timers.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "button.h"
#include "iot_button.h"

#define IOT_CHECK(tag, a, ret) if(!(a)) { \
ESP_LOGE(tag,"%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__); \
Expand Down Expand Up @@ -189,7 +189,7 @@ static void button_free_tmr(xTimerHandle* tmr)
}
}

esp_err_t button_delete(button_handle_t btn_handle)
esp_err_t iot_button_delete(button_handle_t btn_handle)
{
POINT_ASSERT(TAG, btn_handle, ESP_ERR_INVALID_ARG);
button_dev_t* btn = (button_dev_t*) btn_handle;
Expand All @@ -212,7 +212,7 @@ esp_err_t button_delete(button_handle_t btn_handle)
return ESP_OK;
}

button_handle_t button_create(gpio_num_t gpio_num, button_active_t active_level, button_trigger_t trigger, uint32_t serial_thres_sec)
button_handle_t iot_button_create(gpio_num_t gpio_num, button_active_t active_level, button_trigger_t trigger, uint32_t serial_thres_sec)
{
IOT_CHECK(TAG, gpio_num < GPIO_NUM_MAX, NULL);
IOT_CHECK(TAG, serial_thres_sec != 0, NULL);
Expand Down Expand Up @@ -255,7 +255,7 @@ button_handle_t button_create(gpio_num_t gpio_num, button_active_t active_level,
return (button_handle_t) btn;
}

esp_err_t button_rm_cb(button_handle_t btn_handle, button_cb_type_t type)
esp_err_t iot_button_rm_cb(button_handle_t btn_handle, button_cb_type_t type)
{
button_dev_t* btn = (button_dev_t*) btn_handle;
button_cb_t* btn_cb = NULL;
Expand All @@ -275,7 +275,7 @@ esp_err_t button_rm_cb(button_handle_t btn_handle, button_cb_type_t type)
return ESP_OK;
}

esp_err_t button_add_cb(button_handle_t btn_handle, button_cb_type_t type, button_cb cb, void* arg, int interval_tick)
esp_err_t iot_button_add_cb(button_handle_t btn_handle, button_cb_type_t type, button_cb cb, void* arg, int interval_tick)
{
POINT_ASSERT(TAG, btn_handle, ESP_ERR_INVALID_ARG);
IOT_CHECK(TAG, interval_tick > 0, ESP_ERR_INVALID_ARG);
Expand Down Expand Up @@ -306,7 +306,7 @@ esp_err_t button_add_cb(button_handle_t btn_handle, button_cb_type_t type, butto
return ESP_OK;
}

esp_err_t button_add_custom_cb(button_handle_t btn_handle, uint32_t press_sec, button_cb cb, void* arg)
esp_err_t iot_button_add_custom_cb(button_handle_t btn_handle, uint32_t press_sec, button_cb cb, void* arg)
{
POINT_ASSERT(TAG, btn_handle, ESP_ERR_INVALID_ARG);
IOT_CHECK(TAG, press_sec != 0, ESP_ERR_INVALID_ARG);
Expand Down
12 changes: 6 additions & 6 deletions components/button/button_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "button.h"
#include "iot_button.h"

CButton::CButton(gpio_num_t gpio_num, button_active_t active_level, button_trigger_t trigger, uint32_t serial_thres_sec)
{
m_btn_handle = button_create(gpio_num, active_level, trigger, serial_thres_sec);
m_btn_handle = iot_button_create(gpio_num, active_level, trigger, serial_thres_sec);
}

CButton::~CButton()
{
button_delete(m_btn_handle);
iot_button_delete(m_btn_handle);
m_btn_handle = NULL;
}

esp_err_t CButton::add_cb(button_cb_type_t type, button_cb cb, void* arg, int interval_tick)
{
return button_add_cb(m_btn_handle, type, cb, arg, interval_tick);
return iot_button_add_cb(m_btn_handle, type, cb, arg, interval_tick);
}

esp_err_t CButton::add_custom_cb(uint32_t press_sec, button_cb cb, void* arg)
{
return button_add_custom_cb(m_btn_handle, press_sec, cb, arg);
return iot_button_add_custom_cb(m_btn_handle, press_sec, cb, arg);
}

esp_err_t CButton::rm_cb(button_cb_type_t type)
{
return button_rm_cb(m_btn_handle, type);
return iot_button_rm_cb(m_btn_handle, type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef enum {
*
* @return A button_handle_t handle to the created button object, or NULL in case of error.
*/
button_handle_t button_create(gpio_num_t gpio_num, button_active_t active_level, button_trigger_t trigger, uint32_t serial_thres_sec);
button_handle_t iot_button_create(gpio_num_t gpio_num, button_active_t active_level, button_trigger_t trigger, uint32_t serial_thres_sec);

/**
* @brief Register a callback function for a button_cb_type_t action.
Expand All @@ -80,7 +80,7 @@ button_handle_t button_create(gpio_num_t gpio_num, button_active_t active_level,
* - ESP_OK Success
* - ESP_FAIL Parameter error
*/
esp_err_t button_add_cb(button_handle_t btn_handle, button_cb_type_t type, button_cb cb, void* arg, int interval_tick);
esp_err_t iot_button_add_cb(button_handle_t btn_handle, button_cb_type_t type, button_cb cb, void* arg, int interval_tick);

/**
* @brief
Expand All @@ -99,7 +99,7 @@ esp_err_t button_add_cb(button_handle_t btn_handle, button_cb_type_t type, butto
* - ESP_OK Success
* - ESP_FAIL Parameter error
*/
esp_err_t button_add_custom_cb(button_handle_t btn_handle, uint32_t press_sec, button_cb cb, void* arg);
esp_err_t iot_button_add_custom_cb(button_handle_t btn_handle, uint32_t press_sec, button_cb cb, void* arg);

/**
* @brief Delete button object and free memory
Expand All @@ -109,7 +109,7 @@ esp_err_t button_add_custom_cb(button_handle_t btn_handle, uint32_t press_sec, b
* - ESP_OK Success
* - ESP_FAIL Parameter error
*/
esp_err_t button_delete(button_handle_t btn_handle);
esp_err_t iot_button_delete(button_handle_t btn_handle);

/**
* @brief Remove callback
Expand All @@ -120,7 +120,7 @@ esp_err_t button_delete(button_handle_t btn_handle);
* @return
* - ESP_OK Success
*/
esp_err_t button_rm_cb(button_handle_t btn_handle, button_cb_type_t type);
esp_err_t iot_button_rm_cb(button_handle_t btn_handle, button_cb_type_t type);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion components/button/test/button_obj_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "freertos/task.h"
#include "esp_system.h"
#include "unity.h"
#include "button.h"
#include "iot_button.h"
#include "esp_log.h"

#define BUTTON_IO_NUM GPIO_NUM_0
Expand Down
18 changes: 9 additions & 9 deletions components/button/test/button_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "freertos/timers.h"

#include "unity.h"
#include "button.h"
#include "iot_button.h"
#include "esp_system.h"
#include "esp_log.h"

Expand All @@ -59,19 +59,19 @@ void button_press_5s_cb(void* arg)
void button_test()
{
printf("before btn init, heap: %d\n", esp_get_free_heap_size());
button_handle_t btn_handle = button_create(BUTTON_IO_NUM, BUTTON_ACTIVE_LEVEL, BUTTON_SERIAL_TRIGGER, 3);
button_add_cb(btn_handle, BUTTON_PUSH_CB, button_tap_cb, "PUSH", 50 / portTICK_PERIOD_MS);
button_add_cb(btn_handle, BUTTON_RELEASE_CB, button_tap_cb, "RELEASE", 50 / portTICK_PERIOD_MS);
button_add_cb(btn_handle, BUTTON_TAP_CB, button_tap_cb, "TAP", 50 / portTICK_PERIOD_MS);
button_add_cb(btn_handle, BUTTON_SERIAL_CB, button_tap_cb, "SERIAL", 1000 / portTICK_PERIOD_MS);
button_handle_t btn_handle = iot_button_create(BUTTON_IO_NUM, BUTTON_ACTIVE_LEVEL, BUTTON_SERIAL_TRIGGER, 3);
iot_button_add_cb(btn_handle, BUTTON_PUSH_CB, button_tap_cb, "PUSH", 50 / portTICK_PERIOD_MS);
iot_button_add_cb(btn_handle, BUTTON_RELEASE_CB, button_tap_cb, "RELEASE", 50 / portTICK_PERIOD_MS);
iot_button_add_cb(btn_handle, BUTTON_TAP_CB, button_tap_cb, "TAP", 50 / portTICK_PERIOD_MS);
iot_button_add_cb(btn_handle, BUTTON_SERIAL_CB, button_tap_cb, "SERIAL", 1000 / portTICK_PERIOD_MS);

button_add_custom_cb(btn_handle, 2, button_press_2s_cb, NULL);
button_add_custom_cb(btn_handle, 5, button_press_5s_cb, NULL);
iot_button_add_custom_cb(btn_handle, 2, button_press_2s_cb, NULL);
iot_button_add_custom_cb(btn_handle, 5, button_press_5s_cb, NULL);
printf("after btn init, heap: %d\n", esp_get_free_heap_size());

vTaskDelay(400000 / portTICK_PERIOD_MS);
printf("free btn: heap:%d\n", esp_get_free_heap_size());
button_delete(btn_handle);
iot_button_delete(btn_handle);
printf("after free btn: heap:%d\n", esp_get_free_heap_size());
}

Expand Down
8 changes: 4 additions & 4 deletions components/dac_audio/dac_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "freertos/task.h"
#include "driver/i2s.h"
#include "driver/dac.h"
#include "dac_audio.h"
#include "iot_dac_audio.h"

typedef struct {
i2s_port_t i2s_num;
Expand All @@ -36,7 +36,7 @@ typedef struct {
int channel_num;
} dac_audio_t;

dac_audio_handle_t dac_audio_create(i2s_port_t i2s_num, int sample_rate, int sample_bits, i2s_dac_mode_t dac_mode, int dma_size, bool init_i2s)
dac_audio_handle_t iot_dac_audio_create(i2s_port_t i2s_num, int sample_rate, int sample_bits, i2s_dac_mode_t dac_mode, int dma_size, bool init_i2s)
{
dac_audio_t *dac = (dac_audio_t*) calloc(sizeof(dac_audio_t), 1);
if(init_i2s) {
Expand All @@ -56,7 +56,7 @@ dac_audio_handle_t dac_audio_create(i2s_port_t i2s_num, int sample_rate, int sam
return (dac_audio_handle_t) dac;
}

esp_err_t dac_audio_delete(dac_audio_handle_t dac_audio, bool delete_i2s)
esp_err_t iot_dac_audio_delete(dac_audio_handle_t dac_audio, bool delete_i2s)
{
dac_audio_t *dac = (dac_audio_t*) dac_audio;
if (delete_i2s) {
Expand All @@ -67,7 +67,7 @@ esp_err_t dac_audio_delete(dac_audio_handle_t dac_audio, bool delete_i2s)
return ESP_OK;
}

esp_err_t dac_audio_play(dac_audio_handle_t dac_audio, const uint8_t* data, int length, TickType_t ticks_to_wait)
esp_err_t iot_dac_audio_play(dac_audio_handle_t dac_audio, const uint8_t* data, int length, TickType_t ticks_to_wait)
{
dac_audio_t *dac = (dac_audio_t*) dac_audio;
i2s_write_bytes(dac->i2s_num, (const char*) data, length, ticks_to_wait);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef void* dac_audio_handle_t;
* - NULL Fail
* - Others Success
*/
dac_audio_handle_t dac_audio_create(i2s_port_t i2s_num, int sample_rate, int sample_bits, i2s_dac_mode_t dac_mode, int dma_size, bool init_i2s);
dac_audio_handle_t iot_dac_audio_create(i2s_port_t i2s_num, int sample_rate, int sample_bits, i2s_dac_mode_t dac_mode, int dma_size, bool init_i2s);

/**
* @brief Delete and release a DAC object
Expand All @@ -32,7 +32,7 @@ dac_audio_handle_t dac_audio_create(i2s_port_t i2s_num, int sample_rate, int sam
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t dac_audio_delete(dac_audio_handle_t dac_audio, bool delete_i2s);
esp_err_t iot_dac_audio_delete(dac_audio_handle_t dac_audio, bool delete_i2s);

/**
* @brief play audio file
Expand All @@ -43,7 +43,7 @@ esp_err_t dac_audio_delete(dac_audio_handle_t dac_audio, bool delete_i2s);
* @return
* - ESP_OK on success
*/
esp_err_t dac_audio_play(dac_audio_handle_t dac_audio, const uint8_t* data, int length, TickType_t ticks_to_wait);
esp_err_t iot_dac_audio_play(dac_audio_handle_t dac_audio, const uint8_t* data, int length, TickType_t ticks_to_wait);



Expand Down
6 changes: 3 additions & 3 deletions components/dac_audio/test/dac_audio_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2s.h"
#include "dac_audio.h"
#include "iot_dac_audio.h"
#include "unity.h"
#include "ja_alert_e2.h"
#include "ja_alert.h"
Expand Down Expand Up @@ -65,11 +65,11 @@ void audio_test()
{"audio_prompt_02", audio_prompt_e2, sizeof(audio_prompt_e2)},

};
dac = dac_audio_create(0, 8000, 16, I2S_DAC_CHANNEL_RIGHT_EN, 1024, true);
dac = iot_dac_audio_create(0, 8000, 16, I2S_DAC_CHANNEL_RIGHT_EN, 1024, true);
while (1) {
for (int i = 0; i < sizeof(playlist)/sizeof(dac_audio_item_t); i++) {
printf("playing file[%d]: %s\n", i, playlist[i].name);
dac_audio_play(dac, playlist[i].data, playlist[i].length, portMAX_DELAY);
iot_dac_audio_play(dac, playlist[i].data, playlist[i].length, portMAX_DELAY);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
Expand Down
18 changes: 9 additions & 9 deletions components/debugs/debugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "esp_log.h"
#include "esp_wifi.h"
#include "esp_sleep.h"
#include "debugs.h"
#include "iot_debugs.h"

#define IOT_CHECK(tag, a, ret) if(!(a)) { \
ESP_LOGE(tag,"%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__); \
Expand Down Expand Up @@ -129,7 +129,7 @@ static void debug_task(void *arg)
}
}

esp_err_t debug_init(uart_port_t uart_num, int baud_rate, int tx_io, int rx_io)
esp_err_t iot_debug_init(uart_port_t uart_num, int baud_rate, int tx_io, int rx_io)
{
uart_config_t uart_config = {
.baud_rate = baud_rate,
Expand All @@ -150,7 +150,7 @@ esp_err_t debug_init(uart_port_t uart_num, int baud_rate, int tx_io, int rx_io)
return ESP_OK;
}

esp_err_t debug_add_custom_cmd(const char *cmd, debug_cb_t cb, void *arg)
esp_err_t iot_debug_add_custom_cmd(const char *cmd, debug_cb_t cb, void *arg)
{
POINTER_ASSERT(TAG, cmd);
POINTER_ASSERT(TAG, cb);
Expand Down Expand Up @@ -183,33 +183,33 @@ esp_err_t debug_add_custom_cmd(const char *cmd, debug_cb_t cb, void *arg)
return ESP_OK;
}

esp_err_t debug_add_cmd(const char *cmd, debug_cmd_type_t cmd_type)
esp_err_t iot_debug_add_cmd(const char *cmd, debug_cmd_type_t cmd_type)
{
POINTER_ASSERT(TAG, cmd);
switch (cmd_type) {
case DEBUG_CMD_WIFI_INFO:
debug_add_custom_cmd(cmd, wifi_info_log, NULL);
iot_debug_add_custom_cmd(cmd, wifi_info_log, NULL);
break;
case DEBUG_CMD_WAKEUP_INFO:
debug_add_custom_cmd(cmd, wakeup_info_log, NULL);
iot_debug_add_custom_cmd(cmd, wakeup_info_log, NULL);
break;
case DEBUG_CMD_RESTART:
debug_add_custom_cmd(cmd, debug_restart, NULL);
iot_debug_add_custom_cmd(cmd, debug_restart, NULL);
break;
default:
break;
}
return ESP_OK;
}

esp_err_t debug_add_cmd_group(debug_cmd_info_t debug_cmds[], int len)
esp_err_t iot_debug_add_cmd_group(debug_cmd_info_t debug_cmds[], int len)
{
if (len <= 0) {
return ESP_FAIL;
}
for (int i = 0; i < len; i++) {
debug_cmd_info_t cmd_info = debug_cmds[i];
debug_add_custom_cmd(cmd_info.cmd, cmd_info.cb, cmd_info.arg);
iot_debug_add_custom_cmd(cmd_info.cmd, cmd_info.cb, cmd_info.arg);
}
return ESP_OK;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ typedef struct {
* - ESP_OK: succeed
* - others: fail
*/
esp_err_t debug_init(uart_port_t uart_num, int baud_rate, int tx_io, int rx_io);
esp_err_t iot_debug_init(uart_port_t uart_num, int baud_rate, int tx_io, int rx_io);

/**
* @brief add custom debug command
Expand All @@ -70,7 +70,7 @@ esp_err_t debug_init(uart_port_t uart_num, int baud_rate, int tx_io, int rx_io);
* - ESP_OK: succeed
* - others: fail
*/
esp_err_t debug_add_custom_cmd(const char *cmd, debug_cb_t cb, void *arg);
esp_err_t iot_debug_add_custom_cmd(const char *cmd, debug_cb_t cb, void *arg);

/**
* @brief add debug command
Expand All @@ -82,7 +82,7 @@ esp_err_t debug_add_custom_cmd(const char *cmd, debug_cb_t cb, void *arg);
* - ESP_OK: succeed
* - others: fail
*/
esp_err_t debug_add_cmd(const char *cmd, debug_cmd_type_t cmd_type);
esp_err_t iot_debug_add_cmd(const char *cmd, debug_cmd_type_t cmd_type);

/**
* @brief add custom debug commands in batch
Expand All @@ -94,7 +94,7 @@ esp_err_t debug_add_cmd(const char *cmd, debug_cmd_type_t cmd_type);
* - ESP_OK: succeed
* - others: fail
*/
esp_err_t debug_add_cmd_group(debug_cmd_info_t debug_cmds[], int len);
esp_err_t iot_debug_add_cmd_group(debug_cmd_info_t debug_cmds[], int len);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit d335224

Please sign in to comment.