forked from rogerdahl/m5stickc-idf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added LED and compilation define to exlude event for older IDF
- Loading branch information
Showing
10 changed files
with
206 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* m5led.c | ||
* | ||
* (C) 2019 - Teuteuguy | ||
* This code is licensed under the MIT License. | ||
*/ | ||
|
||
#include "m5led.h" | ||
|
||
static const char * TAG = "m5led"; | ||
|
||
static bool current_state = M5LED_DEFAULT_STATE; | ||
|
||
esp_err_t m5led_init() | ||
{ | ||
esp_err_t e; | ||
|
||
gpio_config_t io_conf; | ||
// Setup the LED | ||
io_conf.intr_type = GPIO_PIN_INTR_DISABLE; //disable interrupt | ||
io_conf.mode = GPIO_MODE_OUTPUT; //set as output mode | ||
io_conf.pin_bit_mask = ((1ULL << M5LED_GPIO)); // bit mask of the pins that you want to set, e.g.GPIO10 | ||
io_conf.pull_down_en = 0; //disable pull-down mode | ||
io_conf.pull_up_en = 0; //disable pull-up mode | ||
e = gpio_config(&io_conf); //configure GPIO with the given settings | ||
if (e != ESP_OK) | ||
{ | ||
ESP_LOGE(TAG, "Error setting up LED: %u", e); | ||
return e; | ||
} | ||
|
||
e = gpio_set_level(M5LED_GPIO, M5LED_DEFAULT_STATE); | ||
if (e != ESP_OK) | ||
{ | ||
return ESP_FAIL; | ||
} | ||
|
||
ESP_LOGD(TAG, "LED G10 enabled"); | ||
return ESP_OK; | ||
} | ||
|
||
bool m5led_is_on(void) | ||
{ | ||
return current_state; | ||
} | ||
|
||
esp_err_t m5led_set(bool state) | ||
{ | ||
esp_err_t e; | ||
|
||
current_state = state; | ||
e = gpio_set_level(M5LED_GPIO, current_state); | ||
if (e != ESP_OK) | ||
{ | ||
return ESP_FAIL; | ||
} | ||
|
||
return ESP_OK; | ||
} | ||
|
||
esp_err_t m5led_toggle(void) | ||
{ | ||
esp_err_t e; | ||
|
||
e = m5led_set(1 - current_state); | ||
if (e != ESP_OK) | ||
{ | ||
return ESP_FAIL; | ||
} | ||
|
||
return ESP_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* m5led.h | ||
* | ||
* (C) 2019 - Teuteuguy | ||
* This code is licensed under the MIT License. | ||
*/ | ||
|
||
#ifndef _M5LED_H_ | ||
#define _M5LED_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
#include "esp_system.h" | ||
#include "esp_log.h" | ||
|
||
#define M5LED_ON 0 | ||
#define M5LED_OFF 1 | ||
|
||
#define M5LED_DEFAULT_STATE M5LED_OFF | ||
#define M5LED_GPIO GPIO_NUM_10 | ||
|
||
/** | ||
* @brief Initialize led | ||
* * | ||
* @return ESP_OK success | ||
* ESP_FAIL failed | ||
*/ | ||
esp_err_t m5led_init(); | ||
|
||
/** | ||
* @brief Check if led is on | ||
* | ||
* @return false not on | ||
* true otherwise on | ||
*/ | ||
bool m5led_is_on(void); | ||
|
||
/** | ||
* @brief Set led. | ||
* | ||
* @param state led state to set | ||
* @return ESP_OK success | ||
* ESP_FAIL failed | ||
* ESP_ERR_INVALID_ARG led null or state is invalid | ||
*/ | ||
esp_err_t m5led_set(bool state); | ||
|
||
/** | ||
* @brief Toggle led. | ||
* | ||
* @return ESP_OK success | ||
* ESP_FAIL failed | ||
* ESP_ERR_INVALID_ARG led null or state is invalid | ||
*/ | ||
esp_err_t m5led_toggle(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // _M5BUTTON_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters