Core2 for AWS IoT EduKit BSP 1.5.1
Macros | Enumerations | Functions | Variables
core2forAWS.h File Reference

Functions to initialize and access Core2 for AWS IoT EduKit hardware features. More...

#include "axp192.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "lvgl/lvgl.h"
#include "disp_driver.h"
#include "disp_spi.h"
#include "ft6336u.h"
#include "sk6812.h"
#include "button.h"
#include "mpu6886.h"
#include "bm8563.h"
#include "cryptoauthlib.h"
#include "atecc608.h"
#include "driver/i2s.h"
#include "microphone.h"
#include "speaker.h"
#include "driver/gpio.h"
#include "esp_freertos_hooks.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/uart.h"
#include "i2c_device.h"

Go to the source code of this file.

Macros

#define SK6812_SIDE_LEFT   0
 LEDs on left side of the LED bar. For use with Core2ForAWS_Sk6812_SetSideColor(). More...
 
#define SK6812_SIDE_RIGHT   1
 LEDs on right side of the LED bar. For use with Core2ForAWS_Sk6812_SetSideColor(). More...
 
#define PORT_A_SDA_PIN   GPIO_NUM_32
 The I2C SDA pin on expansion port A. More...
 
#define PORT_A_SCL_PIN   GPIO_NUM_33
 The I2C SCL pin on expansion port A. More...
 
#define PORT_B_ADC_PIN   GPIO_NUM_36
 The ADC pin on expansion port B. More...
 
#define PORT_B_DAC_PIN   GPIO_NUM_26
 The DAC pin on expansion port B. More...
 
#define PORT_C_UART_TX_PIN   GPIO_NUM_14
 The UART transmission pin on expansion port C. More...
 
#define PORT_C_UART_RX_PIN   GPIO_NUM_13
 The UART receiver pin on expansion port C. More...
 
#define PORT_C_UART_NUM   UART_NUM_2
 The default UART controller used for expansion port C. More...
 
#define PORT_A_I2C_STANDARD_BAUD   100000
 The standard baud rate for I2C peripherals connected to Port A. More...
 
#define UART_RX_BUF_SIZE   2048
 The default UART RX ring buffer size. More...
 
#define SPI_HOST_USE   HSPI_HOST
 The SPI2 peripheral that controls the SPI bus. More...
 
#define SPI_DMA_CHAN   2
 DMA channel for SPI bus. More...
 

Enumerations

enum  pin_mode_t {
  NONE , OUTPUT , INPUT , I2C ,
  ADC , DAC , UART
}
 Modes supported by the BSP for the GPIO pins. More...
 

Functions

void Core2ForAWS_Init (void)
 Initializes the power chip with default values, enables battery charging, and initializes all enabled hardware features. More...
 
void Core2ForAWS_Button_Init (void)
 Initializes the button_left, button_middle, button_right virtual buttons using the ft6336u touch controller. More...
 
void Core2ForAWS_Speaker_Enable (uint8_t state)
 Enables or disables the NS4168 speaker amplifier. More...
 
void Core2ForAWS_PMU_Init (uint16_t ldo2_volt, uint16_t ldo3_volt, uint16_t dc2_volt, uint16_t dc3_volt)
 Initializes the AXP192 Power Management Unit (PMU). More...
 
float Core2ForAWS_PMU_GetBatVolt (void)
 Gets the battery voltage with the AXP192. More...
 
float Core2ForAWS_PMU_GetBatCurrent (void)
 Gets the battery current draw with the AXP192. More...
 
void Core2ForAWS_Display_Init (void)
 Initializes the display. More...
 
void Core2ForAWS_Display_SetBrightness (uint8_t brightness)
 Sets the brightness of the display. More...
 
void Core2ForAWS_LED_Enable (uint8_t enable)
 Turns on or off green LED. More...
 
void Core2ForAWS_Motor_SetStrength (uint8_t strength)
 Sets the speed of the vibration motor. More...
 
void Core2ForAWS_Sk6812_Init (void)
 Initializes the SK6812 LED bars. More...
 
void Core2ForAWS_Sk6812_SetColor (uint16_t pos, uint32_t color)
 Sets the color of a single LED in the LED bars. More...
 
void Core2ForAWS_Sk6812_SetSideColor (uint8_t side, uint32_t color)
 Sets the color of all the LEDs on one side of the LED bars. More...
 
void Core2ForAWS_Sk6812_SetBrightness (uint8_t brightness)
 Sets the brightness of the LED bars. More...
 
void Core2ForAWS_Sk6812_Show (void)
 Updates the LEDs in the LED bars with any new values set using Core2ForAWS_Sk6812_SetColor, Core2ForAWS_Sk6812_SetSideColor or Core2ForAWS_Sk6812_SetBrightness. More...
 
void Core2ForAWS_Sk6812_Clear (void)
 Turns off the LEDs in the LED bars and removes any set color. More...
 
esp_err_t Core2ForAWS_SDcard_Mount (const char *mount_path, sdmmc_card_t **out_card)
 Initializes and mounts the SD-Card. More...
 
esp_err_t Core2ForAWS_SDcard_Unmount (const char *mount_path, sdmmc_card_t *out_card)
 Removes the FAT partition and unmounts the SD-Card. More...
 
esp_err_t Core2ForAWS_Port_PinMode (gpio_num_t pin, pin_mode_t mode)
 Sets the pin mode of the specified pin. More...
 
bool Core2ForAWS_Port_Read (gpio_num_t pin)
 Reads the value from a specified digital pin that's set as an input — either 1 (high) or 0 (low). More...
 
esp_err_t Core2ForAWS_Port_Write (gpio_num_t pin, bool level)
 Writes the specified level (0 or 1) to the specified digital pin. More...
 
I2CDevice_t Core2ForAWS_Port_A_I2C_Begin (uint8_t device_address, uint32_t baud)
 Allocates a peripheral connected to expansion port A. More...
 
esp_err_t Core2ForAWS_Port_A_I2C_Read (I2CDevice_t device, uint32_t register_address, uint8_t *data, uint16_t length)
 Reads from I2C peripheral connected to expansion port A. More...
 
esp_err_t Core2ForAWS_Port_A_I2C_Write (I2CDevice_t device, uint32_t register_address, uint8_t *data, uint16_t length)
 Writes to I2C peripheral connected to expansion port A. More...
 
void Core2ForAWS_Port_A_I2C_Close (I2CDevice_t device)
 Frees the configuration pointer to the I2C peripheral connected on port A. More...
 
uint32_t Core2ForAWS_Port_B_ADC_ReadRaw (void)
 Read the raw ADC value from GPIO36. More...
 
uint32_t Core2ForAWS_Port_B_ADC_ReadMilliVolts (void)
 Read the calibrated ADC voltage from GPIO36. More...
 
esp_err_t Core2ForAWS_Port_B_DAC_WriteMilliVolts (uint16_t mvolts)
 Outputs the specified voltage (millivolts) to the DAC. More...
 
esp_err_t Core2ForAWS_Port_C_UART_Begin (uint32_t baud)
 Configures the UART interface at the specified baud rate. More...
 
int Core2ForAWS_Port_C_UART_Send (const char *message, size_t len)
 Sends a specified length of a user defined message over UART2. More...
 
int Core2ForAWS_Port_C_UART_Receive (uint8_t *message_buffer)
 Reads messages in the UART2 receiver ring buffer. More...
 

Variables

SemaphoreHandle_t xGuiSemaphore
 FreeRTOS semaphore to be used when performing any operation on the display. More...
 
Button_tbutton_left
 Left virtual touch button. More...
 
Button_tbutton_middle
 Middle virtual touch button. More...
 
Button_tbutton_right
 Right virtual touch button. More...
 

Detailed Description

Functions to initialize and access Core2 for AWS IoT EduKit hardware features.

Macro Definition Documentation

◆ SK6812_SIDE_LEFT

#define SK6812_SIDE_LEFT   0

LEDs on left side of the LED bar. For use with Core2ForAWS_Sk6812_SetSideColor().

◆ SK6812_SIDE_RIGHT

#define SK6812_SIDE_RIGHT   1

LEDs on right side of the LED bar. For use with Core2ForAWS_Sk6812_SetSideColor().

◆ PORT_A_SDA_PIN

#define PORT_A_SDA_PIN   GPIO_NUM_32

The I2C SDA pin on expansion port A.

This maps to GPIO 32 and can be used as the Serial DAta Line (SDA) pin for I2C bus communication. Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

◆ PORT_A_SCL_PIN

#define PORT_A_SCL_PIN   GPIO_NUM_33

The I2C SCL pin on expansion port A.

This maps to GPIO 33 and can be used as the Serial CLock Line (SCL) pin to synchronize I2C bus communication. Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

◆ PORT_B_ADC_PIN

#define PORT_B_ADC_PIN   GPIO_NUM_36

The ADC pin on expansion port B.

This maps to GPIO 36 and is capable of converting analog signals to digital. Read more about using ADCs with the ESP-IDF.

◆ PORT_B_DAC_PIN

#define PORT_B_DAC_PIN   GPIO_NUM_26

The DAC pin on expansion port B.

This maps to GPIO 26 and is capable of converting digital signals to analog. Read more about using DACs with the ESP-IDF.

◆ PORT_C_UART_TX_PIN

#define PORT_C_UART_TX_PIN   GPIO_NUM_14

The UART transmission pin on expansion port C.

This maps to GPIO 14 and can be used as the transmission channel for UART communication. Read more about UART communications with the ESP-IDF.

◆ PORT_C_UART_RX_PIN

#define PORT_C_UART_RX_PIN   GPIO_NUM_13

The UART receiver pin on expansion port C.

This maps to GPIO 13 and can be used as the receiver channel for UART communication. Read more about UART communications with the ESP-IDF.

◆ PORT_C_UART_NUM

#define PORT_C_UART_NUM   UART_NUM_2

The default UART controller used for expansion port C.

This maps to UART controller UART2. Read more about UART communications with the ESP-IDF.

◆ PORT_A_I2C_STANDARD_BAUD

#define PORT_A_I2C_STANDARD_BAUD   100000

The standard baud rate for I2C peripherals connected to Port A.

This is the standard baud rate for I2C peripherals that are connected on Port A, which is 100KHz. Read more about UART communications with the ESP-IDF.

◆ UART_RX_BUF_SIZE

#define UART_RX_BUF_SIZE   2048

The default UART RX ring buffer size.

This is the default size of the UART interface's receiver ring buffer. Read more about UART communications with the ESP-IDF.

◆ SPI_HOST_USE

#define SPI_HOST_USE   HSPI_HOST

The SPI2 peripheral that controls the SPI bus.

This is peripheral type used for initializing the SPI bus. There are two peripherals connected to the SPI bus, the ILI9342C display controller and the TF/SD card slot.

◆ SPI_DMA_CHAN

#define SPI_DMA_CHAN   2

DMA channel for SPI bus.

This is the channel used by the SPI bus for the ILI9342C display controller and TF/SD card slot.

Enumeration Type Documentation

◆ pin_mode_t

enum pin_mode_t

Modes supported by the BSP for the GPIO pins.

These are the modes supported for the GPIO pins by the BSP. Read more about UART communications with the ESP-IDF.

Enumerator
NONE 

Reset GPIO to default state.

OUTPUT 

Set GPIO to output mode.

INPUT 

Set GPIO to input mode.

I2C 

Enable I2C mode. Only available on Port A—GPIO 32(SDA) and Port A—GPIO 33 (SCL).

ADC 

Enable ADC mode. Only available on Port B—GPIO 36.

DAC 

Enable DAC mode. Only available on Port B—GPIO 26.

UART 

Enable UART RX/TX mode. UART TX only available on Port C—GPIO 14 and UART RX is only available on Port C—GPIO.

  1. Only supports full-duplex UART so setting one pin to UART mode will also set the other pin to UART mode.

Function Documentation

◆ Core2ForAWS_Init()

void Core2ForAWS_Init ( void  )

Initializes the power chip with default values, enables battery charging, and initializes all enabled hardware features.

At minimum, this helper function initializes the AXP192 power management unit (PMU) with the green LED and vibration motor off, as well as initializing the following features (if enabled):

  1. Display — initializes the SPI bus, also powers the controller and backlight to ~50% brightness.
  2. The touch controller via the FT6336U.
  3. Virtual left, middle, right buttons using the touch controller.
  4. The SK6812 side LED bars.
  5. The 6-axis IMU via the MPU6886.
  6. The real-time clock via the BM8563 features.

◆ Core2ForAWS_Button_Init()

void Core2ForAWS_Button_Init ( void  )

Initializes the button_left, button_middle, button_right virtual buttons using the ft6336u touch controller.

Note
The Core2ForAWS_Init() calls this function when the hardware feature is enabled.

◆ Core2ForAWS_Speaker_Enable()

void Core2ForAWS_Speaker_Enable ( uint8_t  state)

Enables or disables the NS4168 speaker amplifier.

Note
The speaker cannot be enabled at the same time as the microphone since they both share a common pin (GPIO0). Attempting to enable and use both at the same time will cause the device to hard fault.
Parameters
[in]stateDesired state of the speaker. 1 to enable, 0 to disable.

◆ Core2ForAWS_PMU_Init()

void Core2ForAWS_PMU_Init ( uint16_t  ldo2_volt,
uint16_t  ldo3_volt,
uint16_t  dc2_volt,
uint16_t  dc3_volt 
)

Initializes the AXP192 Power Management Unit (PMU).

Used to directly initialize the AXP192 LDO2, LDO3, DC2, and DC3 pins.

Note
The Core2ForAWS_Init() calls this function with parameters to initialize the vibration motor and display backlight. If the ILI9342u display hardware feature is enabled, it sets the brightness to ~55% brightness. The vibration motor is always initialized in the off state.
Parameters
[in]ldo2_voltlow-dropout voltage of the display.
[in]ldo3_voltlow-dropout voltage of the vibration motor.
[in]dc2_voltvoltage of the vibration motor.
[in]dc3_voltvoltage of the display.

◆ Core2ForAWS_PMU_GetBatVolt()

float Core2ForAWS_PMU_GetBatVolt ( void  )

Gets the battery voltage with the AXP192.

EXAMPLE Get the current battery voltage in the variable named battery_voltage and print the voltage to the serial output.

float battery_voltage = Core2ForAWS_PMU_GetBatVolt();
printf("Battery Voltage: %0.2f", battery_voltage);
float Core2ForAWS_PMU_GetBatVolt(void)
Gets the battery voltage with the AXP192.
Definition: core2forAWS.c:160
Returns
The voltage of the battery.

◆ Core2ForAWS_PMU_GetBatCurrent()

float Core2ForAWS_PMU_GetBatCurrent ( void  )

Gets the battery current draw with the AXP192.

EXAMPLE Get the current battery current in the variable named battery_current and print the current to the serial output.

float battery_current = Core2ForAWS_PMU_GetBatCurrent();
printf("Battery Current: %0.3f", battery_current);
float Core2ForAWS_PMU_GetBatCurrent(void)
Gets the battery current draw with the AXP192.
Definition: core2forAWS.c:164
Returns
The current draw of the battery.

◆ Core2ForAWS_Display_Init()

void Core2ForAWS_Display_Init ( void  )

Initializes the display.

You must use this to initialize the display before attempting to write to the display. It initializes the ILI9342C on the SPI bus and the LVGL driver.

Note
Creates a FreeRTOS task with the task name gui.
The Core2ForAWS_Init() calls this function when the hardware feature is enabled.

◆ Core2ForAWS_Display_SetBrightness()

void Core2ForAWS_Display_SetBrightness ( uint8_t  brightness)

Sets the brightness of the display.

This function sets the brightness of the display using the AXP192 power management unit. It does not write to the display controller, so it does not require taking the xGuiSemaphore mutex prior to use.

Example:

Set the display brightness to maximum.

void Core2ForAWS_Display_SetBrightness(uint8_t brightness)
Sets the brightness of the display.
Definition: core2forAWS.c:333
Parameters
[in]brightnessthe desired brightness of the display. Accepts a value from 0 to 100.

◆ Core2ForAWS_LED_Enable()

void Core2ForAWS_LED_Enable ( uint8_t  enable)

Turns on or off green LED.

Parameters
[in]enableThe desired state of the LED. 1 to turn on, 0 to turn off.

◆ Core2ForAWS_Motor_SetStrength()

void Core2ForAWS_Motor_SetStrength ( uint8_t  strength)

Sets the speed of the vibration motor.

Parameters
[in]strengthThe desired speed of the motor or strength of the vibration. 0 to turn it off, 255 for maximum speed.

◆ Core2ForAWS_Sk6812_Init()

void Core2ForAWS_Sk6812_Init ( void  )

Initializes the SK6812 LED bars.

You must use this to initialize the LED bars before attempting to use either of the LED bars.

Note
The Core2ForAWS_Init() calls this function when the hardware feature is enabled.

◆ Core2ForAWS_Sk6812_SetColor()

void Core2ForAWS_Sk6812_SetColor ( uint16_t  pos,
uint32_t  color 
)

Sets the color of a single LED in the LED bars.

Note
Requires following with Core2ForAWS_Sk6812_Show() to write the set color to the LEDs.

Example:

Set the color of each of the LEDs to white one at a time every second.

for (uint8_t i = 0; i < 10; i++) {
vTaskDelay(pdMS_TO_TICKS(1000));
}
void Core2ForAWS_Sk6812_SetColor(uint16_t pos, uint32_t color)
Sets the color of a single LED in the LED bars.
Definition: core2forAWS.c:232
void Core2ForAWS_Sk6812_Show(void)
Updates the LEDs in the LED bars with any new values set using Core2ForAWS_Sk6812_SetColor,...
Definition: core2forAWS.c:252
Parameters
[in]posLED to set. Accepts a value from 0 to 9.
[in]colorColor of the LED. Accepts hexadecimal (web colors). 0x000000 is black and 0xffffff is white.
Note
You must use Core2ForAWS_Sk6812_Show() after this function for the setting to take effect.

◆ Core2ForAWS_Sk6812_SetSideColor()

void Core2ForAWS_Sk6812_SetSideColor ( uint8_t  side,
uint32_t  color 
)

Sets the color of all the LEDs on one side of the LED bars.

Note
Requires following with Core2ForAWS_Sk6812_Show() to write the set color to the LEDs.

Example:

Set the left LED bar to green and the right LED bar to red.

void Core2ForAWS_Sk6812_SetSideColor(uint8_t side, uint32_t color)
Sets the color of all the LEDs on one side of the LED bars.
Definition: core2forAWS.c:236
#define SK6812_SIDE_RIGHT
LEDs on right side of the LED bar. For use with Core2ForAWS_Sk6812_SetSideColor().
Definition: core2forAWS.h:64
#define SK6812_SIDE_LEFT
LEDs on left side of the LED bar. For use with Core2ForAWS_Sk6812_SetSideColor().
Definition: core2forAWS.h:57
Parameters
[in]sideSide of LEDs to set. Accepts SK6812_SIDE_LEFT or SK6812_SIDE_RIGHT.
[in]colorColor of LED to set. Accepts hexadecimal (web colors). 0x000000 is black and 0xffffff is white.
Note
You must use Core2ForAWS_Sk6812_Show() after this function for the setting to take effect.

◆ Core2ForAWS_Sk6812_SetBrightness()

void Core2ForAWS_Sk6812_SetBrightness ( uint8_t  brightness)

Sets the brightness of the LED bars.

Note
You must use Core2ForAWS_Sk6812_Show() after this function for the setting to take effect.

Example:

Set the LEDs to full brightness.

void Core2ForAWS_Sk6812_SetBrightness(uint8_t brightness)
Sets the brightness of the LED bars.
Definition: core2forAWS.c:248
Parameters
[in]brightnessBrightness of the LED bars. 0 is off, 100 is full brightness.

◆ Core2ForAWS_Sk6812_Show()

void Core2ForAWS_Sk6812_Show ( void  )

Updates the LEDs in the LED bars with any new values set using Core2ForAWS_Sk6812_SetColor, Core2ForAWS_Sk6812_SetSideColor or Core2ForAWS_Sk6812_SetBrightness.

This function must be executed after setting LED bar values. This saves execution time by updating LEDs once after making multiple changes instead of updating with every change.

◆ Core2ForAWS_Sk6812_Clear()

void Core2ForAWS_Sk6812_Clear ( void  )

Turns off the LEDs in the LED bars and removes any set color.

Note
You must use Core2ForAWS_Sk6812_Show() after this function for the setting to take effect.

Example:

Set the LEDs to full brightness.

void Core2ForAWS_Sk6812_Clear(void)
Turns off the LEDs in the LED bars and removes any set color.
Definition: core2forAWS.c:256

◆ Core2ForAWS_SDcard_Mount()

esp_err_t Core2ForAWS_SDcard_Mount ( const char *  mount_path,
sdmmc_card_t **  out_card 
)

Initializes and mounts the SD-Card.

Note
The SD Card must be mounted before use. The SD card and the screen uses the same SPI bus. In order to avoid conflicts with the screen, you must take the spi_mutex semaphore, then call spi_poll() before accessing the SD card. Once done, give/free the semaphore so the display can take it. The display task will then continue to update the display controller on the SPI bus.

Reading/writing to an inserted SD card can use the standard C functions fopen or fprintf to work with Espressif's virtual file drivers. Visit Espressif's virtual file system component docs for usage.

The example code below, mounts the SD card and then writes a file named hello.txt on the path /sdcard with the contents "Hello <<YOUR SD CARD'S PRODUCT NAME>>!":

Example:

#define MOUNT_POINT "/sdcard"
sdmmc_card_t* card;
esp_err_t err;
xSemaphoreTake(spi_mutex, portMAX_DELAY);
err = Core2ForAWS_Sdcard_Mount(MOUNT_POINT, &card);
FILE* f = fopen(MOUNT_POINT"/hello.txt", "w+")
fprintf(f, "Hello %s!\n", card->cid.name);
fclose(f);
xSemaphoreGive(spi_mutex);
void spi_poll()
Polls the SPI bus for a pending SPI transaction to complete.
Definition: disp_spi.c:34
SemaphoreHandle_t spi_mutex
Semaphore for the shared SPI bus.
Definition: disp_spi.c:21
Parameters
[in]mount_pathThe path where partition should be registered.
[out]out_cardThe pointer to the card information structure. Hold this handle and use it to unmount the card later if needed.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Core2ForAWS_SDcard_Unmount()

esp_err_t Core2ForAWS_SDcard_Unmount ( const char *  mount_path,
sdmmc_card_t *  out_card 
)

Removes the FAT partition and unmounts the SD-Card.

Note
The SD Card must be mounted before use. The SD card and the screen uses the same SPI bus. In order to avoid conflicts with the screen, you must take the spi_mutex semaphore, then call spi_poll() before accessing the SD card. Once done, give/free the semaphore so the display can take it. The display task will then continue to update the display controller on the SPI bus.

To learn more about using the SD card, visit Espressif's virtual file system component docs for usage.

The example code below, mounts the SD card, writes a file named hello.txt on the path /sdcard with the contents "Hello <<YOUR SD CARD'S PRODUCT NAME>>!", and then unmounts the card:

Example:

#define MOUNT_POINT "/sdcard"
sdmmc_card_t* card;
esp_err_t err;
xSemaphoreTake(spi_mutex, portMAX_DELAY);
err = Core2ForAWS_Sdcard_Mount(MOUNT_POINT, &card);
FILE* f = fopen(MOUNT_POINT"/hello.txt", "w+")
fprintf(f, "Hello %s!\n", card->cid.name);
fclose(f);
err = Core2ForAWS_Sdcard_Unmount(MOUNT_POINT, &card);
xSemaphoreGive(spi_mutex);
Parameters
[in]mount_pathThe path where partition should be registered.
[out]out_cardThe card information structure.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Core2ForAWS_Port_PinMode()

esp_err_t Core2ForAWS_Port_PinMode ( gpio_num_t  pin,
pin_mode_t  mode 
)

Sets the pin mode of the specified pin.

This function sets the mode of the pin. The available modes are defined by pin_mode_t. All pins support digital input/ouput of high/low. Only specified pins support digital output, I2C, ADC, DAC, or UART. View the ESP32 datasheet or official ]Espressif GPIO driver documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html)

INPUT sets the pin to be able to perform a digital read. Enables the internal pullup resistor. Voltage should not exceed 3.3v.

OUTPUT sets the pin to be able to perform a digital write. Outputs 3.3v when the pin set to high. Not available on Port B GPIO 36.

I2C checks to ensure the pin you're planning to use is meant for I2C communications. You must use PORT_A_SDA_PIN (same as GPIO 32) for the I2C data pin and PORT_A_SCL_PIN (same as GPIO 33) for the I2C clock line pin. Peripherals attached to expansion port A will use I2C port number 0 (I2C_NUM_0) as the on-board peripherals are on I2C port number 1 (I2C_NUM_1). The APIs provided utilize the built-in pullup resistors on the SDA and SCL lines with the Core2 for AWS IoT EduKit as the I2C controller, and all attached devices as the peripheral.

ADC sets the pin to analog single read mode. Single read mode is suitable for low-frequency sampling operations. Must use PORT_B_ADC_PIN (same as GPIO_NUM_36) since it is the only expansion port pin that is ADC capable.

DAC allows the pin to be set to specified voltages. Must use PORT_B_DAC_PIN (same as GPIO_NUM_26) since it is the only expansion port pin that is DAC capable.

UART enables full-duplex Universal Asynchronous Receiver/ Transmitter (UART) serial communications, utilizing both PORT_C_UART_TX_PIN and PORT_C_UART_RX_PIN for transmiting and receiving data. This function should only be called once for UART since setting one pin to UART will automatically set the other. Must use PORT_C_UART_TX_PIN (same as GPIO_NUM_14) as the UART transmit pin since it is the only expansion port pin that is UART TX capable. Must use PORT_C_UART_RX_PIN (same as GPIO_NUM_13) as the UART receive pin since it is the only expansion port pin that is UART RX capable.

NONE resets the pin and removes frees memory.

The example code below sets the ADC pin (GPIO 36) to ADC mode after initializing the Core2 for AWS IoT EduKit and prints out the result of attempting to set the pin.

Example:

#include <stdio.h>
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "SET_PINMODE_DEMO";
void app_main(void){
esp_err_t err = Core2ForAWS_Port_PinMode(GPIO_NUM_36, ADC);
ESP_LOGI(TAG, "Status of setting the pin: %d", err);
}
esp_err_t Core2ForAWS_Port_PinMode(gpio_num_t pin, pin_mode_t mode)
Sets the pin mode of the specified pin.
Definition: core2forAWS.c:431
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
Functions to initialize and access Core2 for AWS IoT EduKit hardware features.
@ ADC
Enable ADC mode. Only available on Port B—GPIO 36.
Definition: core2forAWS.h:218
#define TAG
Definition: i2c_device.c:10
Parameters
[in]pinThe GPIO pin to set the mode of.
[in]modeThe mode to set the GPIO pin.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Core2ForAWS_Port_Read()

bool Core2ForAWS_Port_Read ( gpio_num_t  pin)

Reads the value from a specified digital pin that's set as an input — either 1 (high) or 0 (low).

Note
pin_mode_t for a GPIO pin must be set to INPUT before using Core2ForAWS_Port_Read for that pin.
Reads high when connected to Vcc.
The AXP192 PMU is configured to output 5v on the expansion port's VCC pin. Some peripherals require 3.3V and requires adjusting the output from the AXP192. This is currently unsupported, but can be acheived using the AXP192 driver (located in the core2forAWS/axp192 folder) for advanced developers.

This function reads if the specified pin is high (1) or low (0). In order for the pin to read high, the connected peripheral must use the available ground and Vcc pins and not an external power source.

The example code sets GPIO 26 (same as PORT_B_DAC_PIN) as an input, creates a FreeRTOS task which periodically (1s) reads from GPIO 26 to see if a compatible peripheral is connected. The task prints the returned value to the serial monitor.

Example:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "DIGITAL_READ_DEMO";
void pin_read_task(){
for(;;){
ESP_LOGI(TAG, "Sensor plugged in (0=no / 1=yes): %d", Core2ForAWS_Port_Read(GPIO_NUM_26));
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void app_main(void){
esp_err_t err = Core2ForAWS_Port_PinMode(GPIO_NUM_26, INPUT);
if (err == ESP_OK){
xTaskCreatePinnedToCore(pin_read_task, "read_pin", 1024*4, NULL, 1, NULL, 1);
}
}
bool Core2ForAWS_Port_Read(gpio_num_t pin)
Reads the value from a specified digital pin that's set as an input — either 1 (high) or 0 (low).
Definition: core2forAWS.c:502
@ INPUT
Set GPIO to input mode.
Definition: core2forAWS.h:215
Parameters
[in]pinThe GPIO pin to read.
Returns
1 for high, 0 for low.

◆ Core2ForAWS_Port_Write()

esp_err_t Core2ForAWS_Port_Write ( gpio_num_t  pin,
bool  level 
)

Writes the specified level (0 or 1) to the specified digital pin.

Note
pin_mode_t for a GPIO pin must be set to OUTPUT before using Core2ForAWS_Port_Write for that pin.
The AXP192 PMU is configured to output 5v on the expansion port's VCC pin. Some peripherals require 3.3V and requires adjusting the output from the AXP192. This is currently unsupported, but can be acheived using the AXP192 driver (located in the core2forAWS/axp192 folder) for advanced developers.

This function sets the specified pin to either high(1) or low(0) digital level.

The example code sets the GPIO 26 (same as PORT_B_DAC_PIN) pin mode to OUTPUT, creates a FreeRTOS task which periodically (1s) toggles GPIO 26 pin between high and low and prints the output level to the serial monitor.

Example:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "DIGITAL_WRITE_DEMO";
void pin_write_task(){
bool output = 0;
for(;;){
Core2ForAWS_Port_Write(GPIO_NUM_26, output);
ESP_LOGI(TAG, "Output on GPIO %d: %s", GPIO_NUM_26, output ? "HIGH" : "LOW");
output = !output;
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void app_main(void){
esp_err_t err = Core2ForAWS_Port_PinMode(GPIO_NUM_26, OUTPUT);
if (err == ESP_OK){
xTaskCreatePinnedToCore(pin_write_task, "write_pin", 1024*4, NULL, 1, NULL, 1);
}
}
esp_err_t Core2ForAWS_Port_Write(gpio_num_t pin, bool level)
Writes the specified level (0 or 1) to the specified digital pin.
Definition: core2forAWS.c:508
@ OUTPUT
Set GPIO to output mode.
Definition: core2forAWS.h:214
Parameters
[in]pinThe GPIO pin to set the digital output level of.
[in]levelThe digital out level of the pin (low = 0, high = 1).
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Core2ForAWS_Port_A_I2C_Begin()

I2CDevice_t Core2ForAWS_Port_A_I2C_Begin ( uint8_t  device_address,
uint32_t  baud 
)

Allocates a peripheral connected to expansion port A.

This function allocates configuration of an attached I2C peripheral on expansion port A with a minimum baud rate of 100,000Hz. The macro PORT_A_I2C_STANDARD_BAUD can used for a generally compatible baud rate for most peripherals. The maximum rate supported by the ESP32-D0WD is 5MHz.

Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

Note
The AXP192 PMU is configured to output 5v on the expansion port's VCC pin. Some peripherals require 3.3V and requires adjusting the output from the AXP192. This is currently unsupported, but can be acheived using the AXP192 driver (located in the core2forAWS/axp192 folder) for advanced developers.

The example code allocates a I2C heart rate sensor peripheral in the variable port_A_peripheral of type I2CDevice_t that has an 8-bit device address of 0xA0 (right-shifted by 1-bit to be a 7-bit address) and using the standard baud rate. It then waits 10 seconds before looping to read from the peripheral, and since the device doesn't take a register address, it uses the macro I2C_NO_REG. The reading is printed every 10 seconds to the serial output.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "core2forAWS.h"
#define DEVICE_ADDRESS 0xA0 >> 1
static const char *TAG = "MAIN";
void i2c_test_task(void * param){
vTaskDelay(pdMS_TO_TICKS(10000));
for(;;){
uint8_t heart_rate = 255;
esp_err_t err = Core2ForAWS_Port_A_I2C_Read(port_A_peripheral, I2C_NO_REG, &heart_rate, 1);
if(!err){
ESP_LOGI(TAG, "Heart Rate — %ubpm", heart_rate);
}
vTaskDelay(pdMS_TO_TICKS(10000));
}
Core2ForAWS_Port_A_I2C_Close(port_A_peripheral);
vTaskDelete(NULL);
}
void app_main()
{
xTaskCreatePinnedToCore(&i2c_test_task, "i2c_test_task", 4096, NULL, 5, NULL, 1);
}
void Core2ForAWS_Port_A_I2C_Close(I2CDevice_t device)
Frees the configuration pointer to the I2C peripheral connected on port A.
Definition: core2forAWS.c:530
I2CDevice_t Core2ForAWS_Port_A_I2C_Begin(uint8_t device_address, uint32_t baud)
Allocates a peripheral connected to expansion port A.
Definition: core2forAWS.c:518
esp_err_t Core2ForAWS_Port_A_I2C_Read(I2CDevice_t device, uint32_t register_address, uint8_t *data, uint16_t length)
Reads from I2C peripheral connected to expansion port A.
Definition: core2forAWS.c:522
#define PORT_A_I2C_STANDARD_BAUD
The standard baud rate for I2C peripherals connected to Port A.
Definition: core2forAWS.h:191
void * I2CDevice_t
A pointer to the I2C peripheral configuration.
Definition: i2c_device.h:41
#define I2C_NO_REG
Used when the I2C peripheral does not use registers for read/write operations.
Definition: i2c_device.h:24
Parameters
[in]device_addressThe 7-bit I2C device address.
[in]baudThe baud rate of I2C communications.
Returns
A pointer to the I2C device configuration.

◆ Core2ForAWS_Port_A_I2C_Read()

esp_err_t Core2ForAWS_Port_A_I2C_Read ( I2CDevice_t  device,
uint32_t  register_address,
uint8_t *  data,
uint16_t  length 
)

Reads from I2C peripheral connected to expansion port A.

This function reads a specified number of bytes starting from the specified register on the peripheral.

Note
Some peripherals do not support specifying a register address to read from. In this scenario, input the I2C_NO_REG macro as the register_address.

Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

The example code allocates a I2C heart rate sensor peripheral called port_A_peripheral of type I2CDevice_t that has an 8-bit device address of 0xA0 (right-shifted by 1-bit to be a 7-bit address) and using the standard baud rate. It then waits 10 seconds before looping to read from the peripheral, and since the device doesn't take a register address, it uses the macro I2C_NO_REG. The reading is printed every 10 seconds to the serial output.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "core2forAWS.h"
#define DEVICE_ADDRESS 0xA0 >> 1
static const char *TAG = "MAIN";
void i2c_test_task(void * param){
vTaskDelay(pdMS_TO_TICKS(10000));
for(;;){
uint8_t heart_rate = 255;
esp_err_t err = Core2ForAWS_Port_A_I2C_Read(port_A_peripheral, I2C_NO_REG, &heart_rate, 1);
if(!err){
ESP_LOGI(TAG, "Heart Rate — %ubpm", heart_rate);
}
vTaskDelay(pdMS_TO_TICKS(10000));
}
Core2ForAWS_Port_A_I2C_Close(port_A_peripheral);
vTaskDelete(NULL);
}
void app_main()
{
xTaskCreatePinnedToCore(&i2c_test_task, "i2c_test_task", 4096, NULL, 5, NULL, 1);
}
Parameters
[in]deviceThe device configuration pointer.
[in]register_addressThe address of the register to begin reading from.
[out]dataThe data read from the register(s).
[in]lengthThe number of bytes to read from the peripheral.
Returns
The I2C device configuration.

◆ Core2ForAWS_Port_A_I2C_Write()

esp_err_t Core2ForAWS_Port_A_I2C_Write ( I2CDevice_t  device,
uint32_t  register_address,
uint8_t *  data,
uint16_t  length 
)

Writes to I2C peripheral connected to expansion port A.

This function writes a specified number of bytes starting from the specified register on the peripheral.

Note
Some peripherals do not support specifying a register address to write to. In this scenario, input the I2C_NO_REG macro as the register_address.

Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

The example code allocates an I2C peripheral called port_A_peripheral of type I2CDevice_t that has a 7-bit device address of 0x68 and uses the standard baud rate. It then writes a single byte of data to a specific register on the device, with a message printed to the serial output if successful.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "core2forAWS.h"
#define DEVICE_ADDRESS 0x68
static const char *TAG = "MAIN";
void app_main()
{
uint8_t my_data = 23;
esp_err_t err = Core2ForAWS_Port_A_I2C_Read(port_A_peripheral, 0x30, &my_data, 1);
if(!err){
ESP_LOGI(TAG, "Successfully wrote to the I2C peripheral");
}
}
Parameters
[in]deviceThe device configuration pointer.
[in]register_addressThe address of the register to begin reading to.
[in]dataThe data to write to the register(s).
[in]lengthThe number of bytes to write to the peripheral.
Returns
The I2C device configuration.

◆ Core2ForAWS_Port_A_I2C_Close()

void Core2ForAWS_Port_A_I2C_Close ( I2CDevice_t  device)

Frees the configuration pointer to the I2C peripheral connected on port A.

This function frees the allocated memory for the pointer that holds the configuration for the I2C device connected on expansion port A. I2C can have multiple peripherals connected on the same bus, using this function to close/free one will not impact the others.

Read more about I2C capabilities of the ESP32 microcontroller and available APIs in the ESP-IDF.

The example code allocates a I2C peripheral called port_A_peripheral of type I2CDevice_t at the standard baud rate. It then closes/frees that device configuration.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "core2forAWS.h"
#define DEVICE_ADDRESS 0xA0 >> 1
static const char *TAG = "MAIN";
void app_main()
{
Core2ForAWS_Port_A_I2C_Close(port_A_peripheral);
}
Parameters
[in]deviceThe device configuration pointer.

◆ Core2ForAWS_Port_B_ADC_ReadRaw()

uint32_t Core2ForAWS_Port_B_ADC_ReadRaw ( void  )

Read the raw ADC value from GPIO36.

Note
Uses the etched eFuse VRef calibration.
pin_mode_t for PORT_B_ADC_PIN must be set to ADC before using Core2ForAWS_Port_B_ADC_ReadRaw.

This function reads the raw ADC value from Port B's Analog-to-Digital-Converter (ADC) on GPIO36. GPIO36 is the only pin on the external ports with access to the ADC. Read more about using ADCs with the ESP-IDF.

The example code sets the ADC pin mode for the PORT_B_ADC_PIN, creates a FreeRTOS task which periodically (1s) reads the raw ADC value of the M5Stack EARTH moisture sensor connected on Port B. It prints out the value to the serial output.

Example:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "RAW_ADC_READ_DEMO";
void read_moisture_task(){
for(;;){
ESP_LOGI(TAG, "Moisture ADC raw: %d", Core2ForAWS_Port_B_ADC_ReadRaw()); *
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void app_main(void){
if(err == ESP_OK){
xTaskCreatePinnedToCore(read_moisture_task, "moisture_raw", 4096*2, NULL, 1, NULL, 1);
}
}
@return The raw ADC reading.
uint32_t Core2ForAWS_Port_B_ADC_ReadRaw(void)
Read the raw ADC value from GPIO36.
Definition: core2forAWS.c:534
#define PORT_B_ADC_PIN
The ADC pin on expansion port B.
Definition: core2forAWS.h:137

◆ Core2ForAWS_Port_B_ADC_ReadMilliVolts()

uint32_t Core2ForAWS_Port_B_ADC_ReadMilliVolts ( void  )

Read the calibrated ADC voltage from GPIO36.

Note
Uses the etched eFuse VRef calibration.
pin_mode_t for PORT_B_ADC_PIN must be set to ADC before using Core2ForAWS_Port_B_ADC_ReadMilliVolts.

This function reads the raw ADC value from Port B's Analog-to-Digital-Converter (ADC) on GPIO36 and converts it to millivolts using the VRef calibration. GPIO36 is the only pin on the external ports with access to the ADC. Read more about using ADCs with the ESP-IDF.

The example code sets the ADC pin mode for the PORT_B_ADC_PIN, creates a FreeRTOS task which periodically (1s) reads the ADC voltage of the M5Stack EARTH moisture sensor connected on Port B. It prints out the value to the serial output.

Example:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "ADC_VOLTAGE_READ_DEMO";
void read_moisture_task(){
for(;;){
ESP_LOGI(TAG, "Moisture ADC converted to voltage: %d", Core2ForAWS_Port_B_ADC_ReadMilliVolts());
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void app_main(void){
if(err == ESP_OK){
xTaskCreatePinnedToCore(read_moisture_task, "moisture_voltage", 1024*4, NULL, 1, NULL, 1);
}
}
uint32_t Core2ForAWS_Port_B_ADC_ReadMilliVolts(void)
Read the calibrated ADC voltage from GPIO36.
Definition: core2forAWS.c:538
Returns
the voltage reading from the ADC in millivolts.

◆ Core2ForAWS_Port_B_DAC_WriteMilliVolts()

esp_err_t Core2ForAWS_Port_B_DAC_WriteMilliVolts ( uint16_t  mvolts)

Outputs the specified voltage (millivolts) to the DAC.

Note
pin_mode_t for PORT_B_DAC_PIN must be set to DAC before using Core2ForAWS_Port_B_DAC_WriteMilliVolts.

This function accepts a range from 0 to a maximum of VDD3P3_RTC (~3300mV).

The example code sets the PORT_B_DAC_PIN (GPIO 26) pin mode to DAC and outputs 1,500mV.

Example:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
void app_main(void){
}
esp_err_t Core2ForAWS_Port_B_DAC_WriteMilliVolts(uint16_t mvolts)
Outputs the specified voltage (millivolts) to the DAC.
Definition: core2forAWS.c:544
@ DAC
Enable DAC mode. Only available on Port B—GPIO 26.
Definition: core2forAWS.h:219
#define PORT_B_DAC_PIN
The DAC pin on expansion port B.
Definition: core2forAWS.h:148
Parameters
[in]mvoltsThe voltage level to set the DAC pin in millivolts.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Core2ForAWS_Port_C_UART_Begin()

esp_err_t Core2ForAWS_Port_C_UART_Begin ( uint32_t  baud)

Configures the UART interface at the specified baud rate.

This is a helper function to simplify building applications with UART. It preconfigures the UART communications with word length of 8 bits, no parity bit, 1 bit for the number of stop bits, and hardware flow control disabled. It sets the baud rate to the user defined value and starts reading from the UART channel 2 and storing data into the ring buffer of length UART_RX_BUF_SIZE.

Usage of the UART convenience methods provided in this BSP aims to simplify development at the expense of compatibility and performance. The configuration above may not be suitable for your application or attached peripheral. For more information about UART communications on the Core2 for AWS IoT EduKit using the ESP32 and how to create your own configuration, visit Espressif's official documentation.

Note
The ESP32 is a 3.3v device and requires 3.3v on the UART TX/RX lines. Higher voltages requires the use of a level shifter.

The example below sets the PORT_C_UART_TX_PIN (GPIO 14) pin mode to UART transmit, which will also set PORT_C_UART_RX_PIN (GPIO 13) to UART receiver, and sets the UART baud rate to 115200. It then starts two FreeRTOS tasks — one that transmits "Hello from AWS IoT EduKit" every two seconds and the other receives the message. The receiver task outputs the number of bytes read from the buffer, the number of bytes that remains unread in the ring buffer, and the message.

To receive the messages transmitted on the same device, run a female-female jumper wire from Port C's TX pin to PORT C's RX pin.

Example:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "UART_DEMO";
static void uart_tx_task(void *arg){
while (1) {
const char *message = "Hello from AWS IoT EduKit";
size_t message_len = strlen(message) + 1;
Core2ForAWS_Port_C_UART_Send(message, message_len);
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
static void uart_rx_task(void *arg){
int rxBytes;
uint8_t *data = heap_caps_malloc(UART_RX_BUF_SIZE, MALLOC_CAP_SPIRAM); // Allocate space for message in external RAM
while (1) {
if (rxBytes > 0) {
ESP_LOGI(TAG, "Read %d bytes from UART. Received: '%s'", rxBytes, data);
}
vTaskDelay(pdMS_TO_TICKS(100)); // Read more frequently than transmit to ensure the messages are not erased from buffer.
}
free(data); // Free memory from external RAM
}
void app_main(void){
if (err == ESP_OK){
xTaskCreate(uart_rx_task, "uart_rx", 1024*2, NULL, configMAX_PRIORITIES, NULL);
xTaskCreate(uart_tx_task, "uart_tx", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
}
}
esp_err_t Core2ForAWS_Port_C_UART_Begin(uint32_t baud)
Configures the UART interface at the specified baud rate.
Definition: core2forAWS.c:549
int Core2ForAWS_Port_C_UART_Receive(uint8_t *message_buffer)
Reads messages in the UART2 receiver ring buffer.
Definition: core2forAWS.c:572
int Core2ForAWS_Port_C_UART_Send(const char *message, size_t len)
Sends a specified length of a user defined message over UART2.
Definition: core2forAWS.c:568
#define UART_RX_BUF_SIZE
The default UART RX ring buffer size.
Definition: core2forAWS.h:202
@ UART
Enable UART RX/TX mode. UART TX only available on Port C—GPIO 14 and UART RX is only available on Por...
Definition: core2forAWS.h:220
#define PORT_C_UART_TX_PIN
The UART transmission pin on expansion port C.
Definition: core2forAWS.h:159
Parameters
[in]baudThe baud rate (bits per second) of the UART2 channel.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Core2ForAWS_Port_C_UART_Send()

int Core2ForAWS_Port_C_UART_Send ( const char *  message,
size_t  len 
)

Sends a specified length of a user defined message over UART2.

This is a helper function to simplify transmitting data over UART using the UART channel 2. This function does not return until all bytes are either transferred from the ring buffer to the hardware FIFO buffer, or already sent.

For more information about UART communications on the Core2 for AWS IoT EduKit using the ESP32, visit Espressif's official documentation.

The example below sets the PORT_C_UART_TX_PIN (GPIO 14) pin mode to UART transmit, which will also set PORT_C_UART_RX_PIN (GPIO 13) to UART receiver, and sets the UART baud rate to 115200. It then starts two FreeRTOS tasks — one that transmits "Hello from AWS IoT EduKit" every two seconds and the other receives the message. The receiver task outputs the number of bytes read from the buffer, the number of bytes that remains unread in the ring buffer, and the message.

To receive the messages transmitted on the same device, run a female-female jumper wire from Port C's TX pin to PORT C's RX pin.

Example:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "UART_DEMO";
static void uart_tx_task(void *arg){
while (1) {
const char *message = "Hello from AWS IoT EduKit";
size_t message_len = strlen(message) + 1;
Core2ForAWS_Port_C_UART_Send(message, message_len);
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
static void uart_rx_task(void *arg){
int rxBytes;
uint8_t *data = heap_caps_malloc(UART_RX_BUF_SIZE, MALLOC_CAP_SPIRAM); // Allocate space for message in external RAM
while (1) {
if (rxBytes > 0) {
ESP_LOGI(TAG, "Read %d bytes from UART. Received: '%s'", rxBytes, data);
}
vTaskDelay(pdMS_TO_TICKS(100)); // Read more frequently than transmit to ensure the messages are not erased from buffer.
}
free(data); // Free memory from external RAM
}
void app_main(void){
if (err == ESP_OK){
xTaskCreate(uart_rx_task, "uart_rx", 1024*2, NULL, configMAX_PRIORITIES, NULL);
xTaskCreate(uart_tx_task, "uart_tx", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
}
}
Parameters
[in]messageA pointer to the message to be transmitted over UART2.
[in]lenThe size of the message that you want to transmit.
Returns
The 0 or greater number of bytes pushed to the TX FIFO. A return value -1 represents an error in one of the provided parameters.

◆ Core2ForAWS_Port_C_UART_Receive()

int Core2ForAWS_Port_C_UART_Receive ( uint8_t *  message_buffer)

Reads messages in the UART2 receiver ring buffer.

This is a helper function to simplify development with UART. This function is used to read messages stored in the receiver hardware FIFO buffer, which was configured to a maximum of UART_RX_BUF_SIZE.

This convenience methods provided in this BSP aims to simplify development at the expense of compatibility and performance. The usage of this function requires regular polling for any new messages. For some applications, it might offer significant performance benefits to set up an interrupt for handling and processing new data. For more information about UART communications on the Core2 for AWS IoT EduKit using the ESP32 and how to create your own configuration, visit Espressif's official documentation.

The example below sets the PORT_C_UART_TX_PIN (GPIO 14) pin mode to UART transmit, which will also set PORT_C_UART_RX_PIN (GPIO 13) to UART receiver, and sets the UART baud rate to 115200. It then starts two FreeRTOS tasks — one that transmits "Hello from AWS IoT EduKit" every two seconds and the other receives the message. The receiver task outputs the number of bytes read from the buffer, the number of bytes that remains unread in the ring buffer, and the message.

To receive the messages transmitted on the same device, run a female-female jumper wire from Port C's TX pin to PORT C's RX pin.

Example:

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "UART_DEMO";
static void uart_tx_task(void *arg){
while (1) {
const char *message = "Hello from AWS IoT EduKit";
size_t message_len = strlen(message) + 1;
Core2ForAWS_Port_C_UART_Send(message, message_len);
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
static void uart_rx_task(void *arg){
int rxBytes;
uint8_t *data = heap_caps_malloc(UART_RX_BUF_SIZE, MALLOC_CAP_SPIRAM); // Allocate space for message in external RAM
while (1) {
if (rxBytes > 0) {
ESP_LOGI(TAG, "Read %d bytes from UART. Received: '%s'", rxBytes, data);
}
vTaskDelay(pdMS_TO_TICKS(100)); // Read more frequently than transmit to ensure the messages are not erased from buffer.
}
free(data); // Free memory from external RAM
}
void app_main(void){
if (err == ESP_OK){
xTaskCreate(uart_rx_task, "uart_rx", 1024*2, NULL, configMAX_PRIORITIES, NULL);
xTaskCreate(uart_tx_task, "uart_tx", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
}
}
Parameters
[out]message_bufferThe buffer which will contain the message read from the receiver hardware FIFO buffer. At maximum, it will be of size UART_RX_BUF_SIZE.
Returns
The number of bytes read from the receiver FIFO buffer.

Variable Documentation

◆ xGuiSemaphore

SemaphoreHandle_t xGuiSemaphore
extern

FreeRTOS semaphore to be used when performing any operation on the display.

To avoid conflicts with multiple threads attempting to write to the display, take this FreeRTOS semaphore first, use the LVGL widget API of choice, and then give the semaphore. The FreeRTOS task, guiTask(), will write to the ILI9342C display controller to update the display.

Example:

Create a LVGL label widget, set the text of the label to "Hello World!", and align the label to the center of the screen.

xSemaphoreTake(xGuiSemaphore, portMAX_DELAY);
lv_obj_t * hello_label = lv_label_create(NULL, NULL);
lv_label_set_text_static(hello_label, "Hello World!");
lv_obj_align(hello_label, NULL, LV_ALIGN_CENTER, 0, 0);
xSemaphoreGive(xGuiSemaphore);
SemaphoreHandle_t xGuiSemaphore
FreeRTOS semaphore to be used when performing any operation on the display.
Definition: core2forAWS.c:271

◆ button_left

Button_t* button_left
extern

Left virtual touch button.

This is a virtual touch button which contains the definitions of a mapped region of the screen that corresponds to the button location and touch events from the FT6336U capacitive touch controller. When the screen is touched in the region that represents the left button, it will update the state of the button. You can use the APIs in the button library with this button as the input parameter to query the button's state.

Example:

Print "left button pressed" when the on-screen left button is pressed.

printf("left button pressed");
}
uint8_t Button_WasPressed(Button_t *button)
See if the specified button was pressed.
Definition: button.c:43
Button_t * button_left
Left virtual touch button.
Definition: core2forAWS.c:85

◆ button_middle

Button_t* button_middle
extern

Middle virtual touch button.

This is a virtual touch button which contains the definitions of a mapped region of the screen that corresponds to the button location and touch events from the FT6336U capacitive touch controller. When the screen is touched in the region that represents the middle button, it will update the state of the button. You can use the APIs in the button library with this button as the input parameter to query the button's state.

Example:

Print "middle button pressed" when the on-screen middle button is pressed.

printf("middle button pressed");
}
Button_t * button_middle
Middle virtual touch button.
Definition: core2forAWS.c:86

◆ button_right

Button_t* button_right
extern

Right virtual touch button.

This is a virtual touch button which contains the definitions of a mapped region of the screen that corresponds to the button location and touch events from the FT6336U capacitive touch controller. When the screen is touched in the region that represents the right button, it will update the state of the button. You can use the APIs in the button library with this button as the input parameter to query the button's state.

Example:

Print "right button pressed" when the on-screen right button is pressed.

printf("right button pressed");
}
Button_t * button_right
Right virtual touch button.
Definition: core2forAWS.c:87