Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard ANSI types in all SDK headers #217

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.project
/.cproject
/.settings/
28 changes: 10 additions & 18 deletions driver_lib/driver/gpio16.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,33 @@
#include "osapi.h"
#include "driver/gpio16.h"

void ICACHE_FLASH_ATTR
gpio16_output_conf(void)
{
void ICACHE_FLASH_ATTR gpio16_output_conf(void) {
WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32_t)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0
(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32_t)0x1); /* mux configuration for XPD_DCDC to output rtc_gpio0 */

WRITE_PERI_REG(RTC_GPIO_CONF,
(READ_PERI_REG(RTC_GPIO_CONF) & (uint32_t)0xfffffffe) | (uint32_t)0x0); //mux configuration for out enable
(READ_PERI_REG(RTC_GPIO_CONF) & (uint32_t)0xfffffffe) | (uint32_t)0x0); /* mux configuration for out enable */

WRITE_PERI_REG(RTC_GPIO_ENABLE,
(READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32_t)0xfffffffe) | (uint32_t)0x1); //out enable
(READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32_t)0xfffffffe) | (uint32_t)0x1); /* out enable */
}

void ICACHE_FLASH_ATTR
gpio16_output_set(uint8_t value)
{
void ICACHE_FLASH_ATTR gpio16_output_set(uint8_t value) {
WRITE_PERI_REG(RTC_GPIO_OUT,
(READ_PERI_REG(RTC_GPIO_OUT) & (uint32_t)0xfffffffe) | (uint32_t)(value & 1));
}

void ICACHE_FLASH_ATTR
gpio16_input_conf(void)
{
void ICACHE_FLASH_ATTR gpio16_input_conf(void) {
WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32_t)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection
(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32_t)0x1); /* mux configuration for XPD_DCDC and rtc_gpio0 connection */

WRITE_PERI_REG(RTC_GPIO_CONF,
(READ_PERI_REG(RTC_GPIO_CONF) & (uint32_t)0xfffffffe) | (uint32_t)0x0); //mux configuration for out enable
(READ_PERI_REG(RTC_GPIO_CONF) & (uint32_t)0xfffffffe) | (uint32_t)0x0); /* mux configuration for out enable */

WRITE_PERI_REG(RTC_GPIO_ENABLE,
READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32_t)0xfffffffe); //out disable
READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32_t)0xfffffffe); /* out disable */
}

uint8_t ICACHE_FLASH_ATTR
gpio16_input_get(void)
{
uint8_t ICACHE_FLASH_ATTR gpio16_input_get(void) {
return (uint8_t)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);
}
4 changes: 2 additions & 2 deletions driver_lib/driver/hw_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void ICACHE_FLASH_ATTR hw_timer_init(frc1_timer_source_type source_type, uint8_t
ETS_FRC1_INTR_ENABLE();
}

//-------------------------------Test Code Below--------------------------------------
/*-------------------------------Test Code Below--------------------------------------*/
#if 0
void hw_test_timer_cb(void)
{
Expand All @@ -128,7 +128,7 @@ void hw_test_timer_cb(void)
j = 0;
}

//hw_timer_arm(50);
/* hw_timer_arm(50); */
}

void ICACHE_FLASH_ATTR user_init(void)
Expand Down
109 changes: 43 additions & 66 deletions driver_lib/driver/i2c_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
*
*/
#include "ets_sys.h"
#include "c_types.h"
#include "osapi.h"
#include "gpio.h"
#include "driver/i2c_master.h"

LOCAL uint8_t m_nLastSDA;
LOCAL uint8_t m_nLastSCL;
static uint8_t m_nLastSDA;
static uint8_t m_nLastSCL;

/******************************************************************************
* FunctionName : i2c_master_setDC
Expand All @@ -37,9 +38,7 @@ LOCAL uint8_t m_nLastSCL;
* uint8_t SCL
* Returns : NONE
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
i2c_master_setDC(uint8_t SDA, uint8_t SCL)
{
static void ICACHE_FLASH_ATTR i2c_master_setDC(uint8_t SDA, uint8_t SCL) {
SDA &= 0x01;
SCL &= 0x01;
m_nLastSDA = SDA;
Expand All @@ -63,9 +62,7 @@ i2c_master_setDC(uint8_t SDA, uint8_t SCL)
* Parameters : NONE
* Returns : uint8_t - SDA bit value
*******************************************************************************/
LOCAL uint8_t ICACHE_FLASH_ATTR
i2c_master_getDC(void)
{
static uint8_t ICACHE_FLASH_ATTR i2c_master_getDC(void) {
uint8_t sda_out;
sda_out = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO));
return sda_out;
Expand All @@ -77,29 +74,27 @@ i2c_master_getDC(void)
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_init(void)
{
void ICACHE_FLASH_ATTR i2c_master_init(void) {
uint8_t i;

i2c_master_setDC(1, 0);
i2c_master_wait(5);

// when SCL = 0, toggle SDA to clear up
/* when SCL = 0, toggle SDA to clear up */
i2c_master_setDC(0, 0) ;
i2c_master_wait(5);
i2c_master_setDC(1, 0) ;
i2c_master_wait(5);

// set data_cnt to max value
/* set data_cnt to max value */
for (i = 0; i < 28; i++) {
i2c_master_setDC(1, 0);
i2c_master_wait(5); // sda 1, scl 0
i2c_master_wait(5); /* sda 1, scl 0 */
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
i2c_master_wait(5); /* sda 1, scl 1 */
}

// reset all
/* reset all */
i2c_master_stop();
return;
}
Expand All @@ -111,24 +106,22 @@ i2c_master_init(void)
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_gpio_init(void)
{
void ICACHE_FLASH_ATTR i2c_master_gpio_init(void) {
ETS_GPIO_INTR_DISABLE() ;
// ETS_INTR_LOCK();
/* ETS_INTR_LOCK(); */

PIN_FUNC_SELECT(I2C_MASTER_SDA_MUX, I2C_MASTER_SDA_FUNC);
PIN_FUNC_SELECT(I2C_MASTER_SCL_MUX, I2C_MASTER_SCL_FUNC);

GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE));
GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SDA_GPIO));
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE));
GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SCL_GPIO));

I2C_MASTER_SDA_HIGH_SCL_HIGH();

ETS_GPIO_INTR_ENABLE() ;
// ETS_INTR_UNLOCK();
/* ETS_INTR_UNLOCK(); */

i2c_master_init();
}
Expand All @@ -139,15 +132,13 @@ i2c_master_gpio_init(void)
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_start(void)
{
void ICACHE_FLASH_ATTR i2c_master_start(void) {
i2c_master_setDC(1, m_nLastSCL);
i2c_master_wait(5);
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
i2c_master_wait(5); /* sda 1, scl 1 */
i2c_master_setDC(0, 1);
i2c_master_wait(5); // sda 0, scl 1
i2c_master_wait(5); /* sda 0, scl 1 */
}

/******************************************************************************
Expand All @@ -156,17 +147,15 @@ i2c_master_start(void)
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_stop(void)
{
void ICACHE_FLASH_ATTR i2c_master_stop(void) {
i2c_master_wait(5);

i2c_master_setDC(0, m_nLastSCL);
i2c_master_wait(5); // sda 0
i2c_master_wait(5); /* sda 0 */
i2c_master_setDC(0, 1);
i2c_master_wait(5); // sda 0, scl 1
i2c_master_wait(5); /* sda 0, scl 1 */
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
i2c_master_wait(5); /* sda 1, scl 1 */
}

/******************************************************************************
Expand All @@ -175,17 +164,15 @@ i2c_master_stop(void)
* Parameters : uint8_t level - 0 or 1
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_setAck(uint8_t level)
{
void ICACHE_FLASH_ATTR i2c_master_setAck(uint8_t level) {
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(5);
i2c_master_setDC(level, 0);
i2c_master_wait(5); // sda level, scl 0
i2c_master_wait(5); /* sda level, scl 0 */
i2c_master_setDC(level, 1);
i2c_master_wait(8); // sda level, scl 1
i2c_master_wait(8); /* sda level, scl 1 */
i2c_master_setDC(level, 0);
i2c_master_wait(5); // sda level, scl 0
i2c_master_wait(5); /* sda level, scl 0 */
i2c_master_setDC(1, 0);
i2c_master_wait(5);
}
Expand All @@ -196,9 +183,7 @@ i2c_master_setAck(uint8_t level)
* Parameters : NONE
* Returns : uint8_t - ack value, 0 or 1
*******************************************************************************/
uint8_t ICACHE_FLASH_ATTR
i2c_master_getAck(void)
{
uint8_t ICACHE_FLASH_ATTR i2c_master_getAck(void) {
uint8_t retVal;
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(5);
Expand All @@ -221,13 +206,12 @@ i2c_master_getAck(void)
* Parameters : NONE
* Returns : true : get ack ; false : get nack
*******************************************************************************/
bool ICACHE_FLASH_ATTR
i2c_master_checkAck(void)
bool ICACHE_FLASH_ATTR i2c_master_checkAck(void)
{
if (i2c_master_getAck()) {
return FALSE;
return false;
} else {
return TRUE;
return true;
}
}

Expand All @@ -237,20 +221,17 @@ i2c_master_checkAck(void)
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_send_ack(void)
{
void ICACHE_FLASH_ATTR i2c_master_send_ack(void) {
i2c_master_setAck(0x0);
}

/******************************************************************************
* FunctionName : i2c_master_send_nack
* Description : response nack
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_send_nack(void)
{
void ICACHE_FLASH_ATTR i2c_master_send_nack(void) {
i2c_master_setAck(0x1);
}

Expand All @@ -260,36 +241,34 @@ i2c_master_send_nack(void)
* Parameters : NONE
* Returns : uint8_t - readed value
*******************************************************************************/
uint8_t ICACHE_FLASH_ATTR
i2c_master_readByte(void)
{
uint8_t ICACHE_FLASH_ATTR i2c_master_readByte(void) {
uint8_t retVal = 0;
uint8_t k, i;

i2c_master_wait(5);
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(5); // sda 1, scl 0
i2c_master_wait(5); /* sda 1, scl 0 */

for (i = 0; i < 8; i++) {
i2c_master_wait(5);
i2c_master_setDC(1, 0);
i2c_master_wait(5); // sda 1, scl 0
i2c_master_wait(5); /* sda 1, scl 0 */
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
i2c_master_wait(5); /* sda 1, scl 1 */

k = i2c_master_getDC();
i2c_master_wait(5);

if (i == 7) {
i2c_master_wait(3); ////
i2c_master_wait(3);
}

k <<= (7 - i);
retVal |= k;
}

i2c_master_setDC(1, 0);
i2c_master_wait(5); // sda 1, scl 0
i2c_master_wait(5); /* sda 1, scl 0 */

return retVal;
}
Expand All @@ -300,11 +279,9 @@ i2c_master_readByte(void)
* Parameters : uint8_t wrdata - write value
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_writeByte(uint8_t wrdata)
{
void ICACHE_FLASH_ATTR i2c_master_writeByte(uint8_t wrdata) {
uint8_t dat;
sint8 i;
int8_t i;

i2c_master_wait(5);

Expand All @@ -319,7 +296,7 @@ i2c_master_writeByte(uint8_t wrdata)
i2c_master_wait(5);

if (i == 0) {
i2c_master_wait(3); ////
i2c_master_wait(3);
}

i2c_master_setDC(dat, 0);
Expand Down
Loading