Anda di halaman 1dari 7

Translation BSFrance contact@bsfrance.

fr jan 2016

SDK esp_iot_sdk_v1.3.0

Please find archive and original un-translated documentation here :


http://bbs.espressif.com/index.php,
SDK build environment can be found here :
http://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=650&extra=page%3D1

IDE and Firmware editing instruction:

1. Launch ESP8266 IDE

2. Use File-Import-Existing Code as Makefile Project and then select the option : Cygwin GCC.
Finally, browse and select esp_iot_sdk_v1.3.0_light_gizwits_2015-11-5_release




Open project view :

AI-THINKER
TECHNOLOGY 1
Translation BSFrance contact@bsfrance.fr jan 2016

RGB LED driver is implemented in the following files :



Light.c

AI-THINKER
TECHNOLOGY 2
Translation BSFrance contact@bsfrance.fr jan 2016

void ICACHE_FLASH_ATTR LED_Init(void){


//setup GPIO function for LED pin
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U , FUNC_GPIO13);
}

void ICACHE_FLASH_ATTR RLED_ON(void){
LED_State=1;
GPIO_OUTPUT_SET(15, LED_State);//set GPIO15 as HIGH
}
void ICACHE_FLASH_ATTR GLED_ON(void){
LED_State=1;
GPIO_OUTPUT_SET(12, LED_State);//set GPIO12 as HIGH
}
void ICACHE_FLASH_ATTR BLED_ON(void){
LED_State=1;
GPIO_OUTPUT_SET(13, LED_State);//GPIO13 as HIGH
}
void ICACHE_FLASH_ATTR RLED_OFF(void){
LED_State=0;
GPIO_OUTPUT_SET(15, LED_State);//GPIO15 as LOW
}
void ICACHE_FLASH_ATTR GLED_OFF(void){
LED_State=0;
GPIO_OUTPUT_SET(12, LED_State);//GPIO12 as LOW
}
void ICACHE_FLASH_ATTR BLED_OFF(void){
LED_State=0;
GPIO_OUTPUT_SET(13, LED_State);//GPIO13 as LOW
}
void ICACHE_FLASH_ATTR LED_Flash(void){
LED_State=!LED_State;
GPIO_OUTPUT_SET(12, LED_State);//reverse LED state
}








AI-THINKER
TECHNOLOGY 3
Translation BSFrance contact@bsfrance.fr jan 2016

Light.h

#ifndef APP_INCLUDE_DRIVER_LED_H_
#define APP_INCLUDE_DRIVER_LED_H_

#include "c_types.h"


extern u8 LED_State;

void LED_Init(void);

void GLED_OFF(void);
void RLED_OFF(void);
void BLED_OFF(void);

void GLED_ON(void);
void RLED_ON(void);
void BLED_ON(void);

void LED_Flash(void);

#endif /* APP_INCLUDE_DRIVER_LED_H_ *




Main.c
#include "osapi.h"
#include "user_config.h"
#include "user_interface.h"
#include "change_ssid.h"
#include "platform.h"
#include "uart.h"
#include "main.h"
#include "light.h"
os_timer_t *mytimer; //timer sructure

void ICACHE_FLASH_ATTR system_init_done()
{
os_printf("\r\nSDK version:%s\r\n", system_get_sdk_version()); //get SDK version
os_printf("\r\nready\r\n");

AI-THINKER
TECHNOLOGY 4
Translation BSFrance contact@bsfrance.fr jan 2016

// Init platform
//platform_init();
}
void Mytime_Fuction(void) //callback function
{
GLED_ON(); //set on
os_delay_us(300000);//OS delay for 300ms
GLED_OFF();//set off

BLED_ON();
os_delay_us(300000);
BLED_OFF();

RLED_ON();
os_delay_us(300000);
RLED_OFF();
}
ICACHE_FLASH_ATTR void main(int argc, char *argv[])
{
UART_SetPrintPort(UART0);//select UART0
uart_div_modify(0, 80 * 1000000 / 115200);//set baudrate to 115200
system_init_done();//initialize system via SDK
os_delay_us(100);//set OS tick to 100us
os_printf("\r\nLED TEST\r\n");
LED_Init();//initialize LED related
os_timer_disarm(&mytimer); //timer structure must be initialized at first
os_timer_setfn(&mytimer,
(ETSTimerFunc *)Mytime_Fuction,
NULL); //callback function and params init
os_timer_arm(&mytimer,1000,1); //start timer, periodic, 1000ms cycle

}



ESP8266 ADC and Timer

ADC functions are called directly from the SDK )(system_adc_read())


#include "osapi.h"
#include "user_config.h"
#include "user_interface.h"
#include "change_ssid.h"

AI-THINKER
TECHNOLOGY 5
Translation BSFrance contact@bsfrance.fr jan 2016

#include "platform.h"
#include "uart.h"//serial
#include "main.h"

os_timer_t *mytimer; //Timer structure

void ICACHE_FLASH_ATTR system_init_done()
{
os_printf("\r\nSDK version:%s\r\n", system_get_sdk_version()); //get SDK version
os_printf("\r\nready\r\n");
//Init platform
//platform_init();
}

void Get_ADC_Value(void) //Get ADC channel value
{
uint8 value_A[4]; //array declaration
uint8 *p=&value_A[0];
uart0_sendStr("\r\n==========ADC Test=============\r\n");
value_A[0]=(system_adc_read())/1000+'0';//data separated for printing
value_A[1]=(system_adc_read())/100%10+'0';
value_A[2]=(system_adc_read())/10%10+'0';
value_A[3]=(system_adc_read())%10+'0';
uart0_sendStr("ADC_VAL : ");
uart0_tx_buffer(p,4);//Transmit data block
uart0_sendStr("\r\n===============================\r\n");
uart0_sendStr("\r\n");


}

void Mytime_Fuction(void) //Callback function
{
Get_ADC_Value();
}


ICACHE_FLASH_ATTR void main(int argc, char *argv[])
{
// Set baudrate
UART_SetPrintPort(UART0);//select UART0
uart_div_modify(0, 80 * 1000000 / 115200);//set baudrate to 115200
system_init_done();//initialize system via SDK
os_delay_us(100);//set OS tick to 100us

AI-THINKER
TECHNOLOGY 6
Translation BSFrance contact@bsfrance.fr jan 2016

os_printf("\r\nADC TEST\r\n");
os_timer_disarm(&mytimer); //at first initialize the time structure
os_timer_setfn(&mytimer,
(ETSTimerFunc *)Mytime_Fuction,
NULL); //configure callback function and params
os_timer_arm(&mytimer,1000,1); //start timer, periodic, 1000ms cycle

}

AI-THINKER
TECHNOLOGY 7

Anda mungkin juga menyukai