I'm new in the world of ESP32.
I'm starting studing esp32 with Visual Studio Code ESP-IDF extension (463a9d8b).I can create basic project like blink, gpio, interrupts using C programming.
Now i want to study C++ programming with ESP-IDF, I have created a basic class with no problems, i have used
Code: Select all
extern "C" void app_main(){
Next step was create a more complex Class used to drive Shift Registers as an exercise.
I was following my previous steps used for the basic class as above :
create a ShiftR.h file :
Code: Select all
#ifndef SHIFTR_H
#define SHIFTR_H
#include <stdio.h>
#include <stdlib.h>
#include <cstddef>
#include "driver/gpio.h"
#define LSBFIRST 0
#define MSBFIRST 1
#define HIGH 1
#define LOW 0
using namespace std;
class ShiftR
{
private:
gpio_num_t latchPin;
gpio_num_t dataPin;
gpio_num_t clockPin;
uint8_t nChip;
unsigned long long bitMask;
public:
void begin(gpio_num_t latch, gpio_num_t clk, gpio_num_t data, uint8_t n);
void ShiftOut(uint32_t value, uint8_t bitOrder);
};
#endif
Code: Select all
#include "ShiftR.h"
void ShiftR::begin(gpio_num_t latch, gpio_num_t clk, gpio_num_t data, uint8_t n)
{
clockPin = clk;
latchPin = latch;
dataPin = data;
nChip =n; //Numbers of chip in series
bitMask = ((1ULL<<clockPin) |(1ULL<<latchPin) | (1ULL<<dataPin));
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = bitMask;
//disable pull-down mode
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
//disable pull-up mode
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
//configure GPIO with the given settings
gpio_config(&io_conf);
}
void ShiftR::ShiftOut(uint32_t value, uint8_t bitOrder)
{
uint8_t value_8;
for(int j=0; j< nChip; j++ ) //For each Byte
{
value_8 = (byte)(value>>(8*j)); //calulate the BYTE to be written
for(int i=0; i<8 ;i++) //For each bit
{
if (bitOrder == LSBFIRST)
gpio_set_level(dataPin, !!(value_8 & (1 << i)));
else
gpio_set_level(dataPin, !!(value_8 & (1 << (7 - i))));
gpio_set_level(clockPin, HIGH);
gpio_set_level(clockPin, LOW);
}
}
}
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "ShiftR.h"
extern "C" void app_main(void)
{
printf("Start!\n");
ShiftR shiftA;
shiftA.begin(18,19,21,1);
}
Code: Select all
...
-- Build files have been written to: C:/ESP_IDF/06_Shift_Register/build
[1/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/sdspi_transaction.c.obj
[2/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/sigmadelta.c.obj
[3/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/sdmmc_transaction.c.obj
[4/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/sdmmc_host.c.obj
[5/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/spi_common.c.obj
[6/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/gpio.c.obj
[7/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/can.c.obj
[8/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/sdspi_host.c.obj
[9/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/ledc.c.obj
[10/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/rmt.c.obj
[11/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/pcnt.c.obj
[12/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/mcpwm.c.obj
[13/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/spi_slave.c.obj
[14/55] Building C object esp-idf/espcoredump/CMakeFiles/__idf_espcoredump.dir/src/core_dump_uart.c.obj
[15/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/i2s.c.obj
[16/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/spi_master.c.obj
[17/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/i2c.c.obj
[18/55] Building C object esp-idf/esp32/CMakeFiles/__idf_esp32.dir/pm_trace.c.obj
[19/55] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/sdio_slave.c.obj
[20/55] Performing build step for 'bootloader'
ninja: no work to do.
[21/53] Building C object esp-idf/esp32/CMakeFiles/__idf_esp32.dir/spiram_psram.c.obj
[22/53] Building C object esp-idf/esp32/CMakeFiles/__idf_esp32.dir/cpu_start.c.obj
[23/53] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/uart.c.obj
[24/53] Building C object esp-idf/driver/CMakeFiles/__idf_driver.dir/rtc_module.c.obj
[25/53] Building C object esp-idf/esp32/CMakeFiles/__idf_esp32.dir/pm_esp32.c.obj
[26/53] Building C object esp-idf/spi_flash/CMakeFiles/__idf_spi_flash.dir/esp_flash_spi_init.c.obj
[27/53] Building C object esp-idf/esp32/CMakeFiles/__idf_esp32.dir/sleep_modes.c.obj
[28/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_phy_dp83848.c.obj
[29/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_phy_dm9051.c.obj
[30/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_phy_lan8720.c.obj
[31/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_phy_ip101.c.obj
[32/53] Building C object esp-idf/esp_adc_cal/CMakeFiles/__idf_esp_adc_cal.dir/esp_adc_cal.c.obj
[33/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_phy_rtl8201.c.obj
[34/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_mac_dm9051.c.obj
[35/53] Linking CXX static library esp-idf\esp32\libesp32.a
[36/53] Building C object esp-idf/esp_eth/CMakeFiles/__idf_esp_eth.dir/src/esp_eth_mac_esp32.c.obj
[37/53] Building C object esp-idf/fatfs/CMakeFiles/__idf_fatfs.dir/vfs/vfs_fat_sdmmc.c.obj
[38/53] Linking CXX static library esp-idf\espcoredump\libespcoredump.a
[39/53] Building C object esp-idf/fatfs/CMakeFiles/__idf_fatfs.dir/vfs/vfs_fat_spiflash.c.obj
[40/53] Building CXX object esp-idf/main/CMakeFiles/__idf_main.dir/ShiftR.cpp.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/ShiftR.cpp.obj
C:\Users\Admin\.espressif\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -IC:/Users/Admin/esp-idf/components/newlib/platform_include -IC:/Users/Admin/esp-idf/components/freertos/include -IC:/Users/Admin/esp-idf/components/heap/include -IC:/Users/Admin/esp-idf/components/log/include -IC:/Users/Admin/esp-idf/components/soc/esp32/include -IC:/Users/Admin/esp-idf/components/soc/include -IC:/Users/Admin/esp-idf/components/esp_rom/include -IC:/Users/Admin/esp-idf/components/esp_common/include -IC:/Users/Admin/esp-idf/components/xtensa/include -IC:/Users/Admin/esp-idf/components/xtensa/esp32/include -IC:/Users/Admin/esp-idf/components/esp32/include -IC:/Users/Admin/esp-idf/components/driver/include -IC:/Users/Admin/esp-idf/components/esp_ringbuf/include -IC:/Users/Admin/esp-idf/components/esp_event/include -IC:/Users/Admin/esp-idf/components/tcpip_adapter/include -IC:/Users/Admin/esp-idf/components/lwip/include/apps -IC:/Users/Admin/esp-idf/components/lwip/include/apps/sntp -IC:/Users/Admin/esp-idf/components/lwip/lwip/src/include -IC:/Users/Admin/esp-idf/components/lwip/port/esp32/include -IC:/Users/Admin/esp-idf/components/lwip/port/esp32/include/arch -IC:/Users/Admin/esp-idf/components/vfs/include -IC:/Users/Admin/esp-idf/components/esp_wifi/include -IC:/Users/Admin/esp-idf/components/esp_wifi/esp32/include -IC:/Users/Admin/esp-idf/components/esp_eth/include -IC:/Users/Admin/esp-idf/components/efuse/include -IC:/Users/Admin/esp-idf/components/efuse/esp32/include -IC:/Users/Admin/esp-idf/components/app_trace/include -IC:/Users/Admin/esp-idf/components/mbedtls/port/include -IC:/Users/Admin/esp-idf/components/mbedtls/mbedtls/include -IC:/Users/Admin/esp-idf/components/wpa_supplicant/include -IC:/Users/Admin/esp-idf/components/wpa_supplicant/port/include -IC:/Users/Admin/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/Users/Admin/esp-idf/components/bootloader_support/include -IC:/Users/Admin/esp-idf/components/app_update/include -IC:/Users/Admin/esp-idf/components/spi_flash/include -IC:/Users/Admin/esp-idf/components/nvs_flash/include -IC:/Users/Admin/esp-idf/components/pthread/include -IC:/Users/Admin/esp-idf/components/espcoredump/include -IC:/Users/Admin/esp-idf/components/asio/asio/asio/include -IC:/Users/Admin/esp-idf/components/asio/port/include -IC:/Users/Admin/esp-idf/components/coap/port/include -IC:/Users/Admin/esp-idf/components/coap/port/include/coap -IC:/Users/Admin/esp-idf/components/coap/libcoap/include -IC:/Users/Admin/esp-idf/components/coap/libcoap/include/coap2 -IC:/Users/Admin/esp-idf/components/console -IC:/Users/Admin/esp-idf/components/nghttp/port/include -IC:/Users/Admin/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/Users/Admin/esp-idf/components/esp-tls -IC:/Users/Admin/esp-idf/components/esp_adc_cal/include -IC:/Users/Admin/esp-idf/components/esp_gdbstub/include -IC:/Users/Admin/esp-idf/components/tcp_transport/include -IC:/Users/Admin/esp-idf/components/esp_http_client/include -IC:/Users/Admin/esp-idf/components/esp_http_server/include -IC:/Users/Admin/esp-idf/components/esp_https_ota/include -IC:/Users/Admin/esp-idf/components/protobuf-c/protobuf-c -IC:/Users/Admin/esp-idf/components/protocomm/include/common -IC:/Users/Admin/esp-idf/components/protocomm/include/security -IC:/Users/Admin/esp-idf/components/protocomm/include/transports -IC:/Users/Admin/esp-idf/components/mdns/include -IC:/Users/Admin/esp-idf/components/esp_local_ctrl/include -IC:/Users/Admin/esp-idf/components/esp_websocket_client/include -IC:/Users/Admin/esp-idf/components/expat/expat/expat/lib -IC:/Users/Admin/esp-idf/components/expat/port/include -IC:/Users/Admin/esp-idf/components/wear_levelling/include -IC:/Users/Admin/esp-idf/components/sdmmc/include -IC:/Users/Admin/esp-idf/components/fatfs/diskio -IC:/Users/Admin/esp-idf/components/fatfs/vfs -IC:/Users/Admin/esp-idf/components/fatfs/src -IC:/Users/Admin/esp-idf/components/freemodbus/common/include -IC:/Users/Admin/esp-idf/components/idf_test/include -IC:/Users/Admin/esp-idf/components/jsmn/include -IC:/Users/Admin/esp-idf/components/json/cJSON -IC:/Users/Admin/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/Users/Admin/esp-idf/components/libsodium/port_include -IC:/Users/Admin/esp-idf/components/mqtt/esp-mqtt/include -IC:/Users/Admin/esp-idf/components/openssl/include -IC:/Users/Admin/esp-idf/components/spiffs/include -IC:/Users/Admin/esp-idf/components/ulp/include -IC:/Users/Admin/esp-idf/components/unity/include -IC:/Users/Admin/esp-idf/components/unity/unity/src -IC:/Users/Admin/esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -std=gnu++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -DIDF_VER=\"v4.0-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/ShiftR.cpp.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\ShiftR.cpp.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/ShiftR.cpp.obj -c ../main/ShiftR.cpp
../main/ShiftR.cpp: In member function 'void ShiftR::begin(gpio_num_t, gpio_num_t, gpio_num_t, uint8_t)':
../main/ShiftR.cpp:15:25: error: cannot convert 'GPIO_INT_TYPE' to 'gpio_int_type_t' in assignment
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
^~~~~~~~~~~~~~~~~~~~~
../main/ShiftR.cpp: In member function 'void ShiftR::ShiftOut(uint32_t, uint8_t)':
../main/ShiftR.cpp:35:20: error: 'byte' was not declared in this scope
value_8 = (byte)(value>>(8*j)); //calulate the BYTE to be written
^~~~
../main/ShiftR.cpp:35:20: note: suggested alternative: 'system'
value_8 = (byte)(value>>(8*j)); //calulate the BYTE to be written
^~~~
system
[41/53] Linking CXX static library esp-idf\esp_eth\libesp_eth.a
[42/53] Building C object esp-idf/freemodbus/CMakeFiles/__idf_freemodbus.dir/port/portserial.c.obj
[43/53] Building CXX object esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj
C:\Users\Admin\.espressif\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -IC:/Users/Admin/esp-idf/components/newlib/platform_include -IC:/Users/Admin/esp-idf/components/freertos/include -IC:/Users/Admin/esp-idf/components/heap/include -IC:/Users/Admin/esp-idf/components/log/include -IC:/Users/Admin/esp-idf/components/soc/esp32/include -IC:/Users/Admin/esp-idf/components/soc/include -IC:/Users/Admin/esp-idf/components/esp_rom/include -IC:/Users/Admin/esp-idf/components/esp_common/include -IC:/Users/Admin/esp-idf/components/xtensa/include -IC:/Users/Admin/esp-idf/components/xtensa/esp32/include -IC:/Users/Admin/esp-idf/components/esp32/include -IC:/Users/Admin/esp-idf/components/driver/include -IC:/Users/Admin/esp-idf/components/esp_ringbuf/include -IC:/Users/Admin/esp-idf/components/esp_event/include -IC:/Users/Admin/esp-idf/components/tcpip_adapter/include -IC:/Users/Admin/esp-idf/components/lwip/include/apps -IC:/Users/Admin/esp-idf/components/lwip/include/apps/sntp -IC:/Users/Admin/esp-idf/components/lwip/lwip/src/include -IC:/Users/Admin/esp-idf/components/lwip/port/esp32/include -IC:/Users/Admin/esp-idf/components/lwip/port/esp32/include/arch -IC:/Users/Admin/esp-idf/components/vfs/include -IC:/Users/Admin/esp-idf/components/esp_wifi/include -IC:/Users/Admin/esp-idf/components/esp_wifi/esp32/include -IC:/Users/Admin/esp-idf/components/esp_eth/include -IC:/Users/Admin/esp-idf/components/efuse/include -IC:/Users/Admin/esp-idf/components/efuse/esp32/include -IC:/Users/Admin/esp-idf/components/app_trace/include -IC:/Users/Admin/esp-idf/components/mbedtls/port/include -IC:/Users/Admin/esp-idf/components/mbedtls/mbedtls/include -IC:/Users/Admin/esp-idf/components/wpa_supplicant/include -IC:/Users/Admin/esp-idf/components/wpa_supplicant/port/include -IC:/Users/Admin/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/Users/Admin/esp-idf/components/bootloader_support/include -IC:/Users/Admin/esp-idf/components/app_update/include -IC:/Users/Admin/esp-idf/components/spi_flash/include -IC:/Users/Admin/esp-idf/components/nvs_flash/include -IC:/Users/Admin/esp-idf/components/pthread/include -IC:/Users/Admin/esp-idf/components/espcoredump/include -IC:/Users/Admin/esp-idf/components/asio/asio/asio/include -IC:/Users/Admin/esp-idf/components/asio/port/include -IC:/Users/Admin/esp-idf/components/coap/port/include -IC:/Users/Admin/esp-idf/components/coap/port/include/coap -IC:/Users/Admin/esp-idf/components/coap/libcoap/include -IC:/Users/Admin/esp-idf/components/coap/libcoap/include/coap2 -IC:/Users/Admin/esp-idf/components/console -IC:/Users/Admin/esp-idf/components/nghttp/port/include -IC:/Users/Admin/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/Users/Admin/esp-idf/components/esp-tls -IC:/Users/Admin/esp-idf/components/esp_adc_cal/include -IC:/Users/Admin/esp-idf/components/esp_gdbstub/include -IC:/Users/Admin/esp-idf/components/tcp_transport/include -IC:/Users/Admin/esp-idf/components/esp_http_client/include -IC:/Users/Admin/esp-idf/components/esp_http_server/include -IC:/Users/Admin/esp-idf/components/esp_https_ota/include -IC:/Users/Admin/esp-idf/components/protobuf-c/protobuf-c -IC:/Users/Admin/esp-idf/components/protocomm/include/common -IC:/Users/Admin/esp-idf/components/protocomm/include/security -IC:/Users/Admin/esp-idf/components/protocomm/include/transports -IC:/Users/Admin/esp-idf/components/mdns/include -IC:/Users/Admin/esp-idf/components/esp_local_ctrl/include -IC:/Users/Admin/esp-idf/components/esp_websocket_client/include -IC:/Users/Admin/esp-idf/components/expat/expat/expat/lib -IC:/Users/Admin/esp-idf/components/expat/port/include -IC:/Users/Admin/esp-idf/components/wear_levelling/include -IC:/Users/Admin/esp-idf/components/sdmmc/include -IC:/Users/Admin/esp-idf/components/fatfs/diskio -IC:/Users/Admin/esp-idf/components/fatfs/vfs -IC:/Users/Admin/esp-idf/components/fatfs/src -IC:/Users/Admin/esp-idf/components/freemodbus/common/include -IC:/Users/Admin/esp-idf/components/idf_test/include -IC:/Users/Admin/esp-idf/components/jsmn/include -IC:/Users/Admin/esp-idf/components/json/cJSON -IC:/Users/Admin/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/Users/Admin/esp-idf/components/libsodium/port_include -IC:/Users/Admin/esp-idf/components/mqtt/esp-mqtt/include -IC:/Users/Admin/esp-idf/components/openssl/include -IC:/Users/Admin/esp-idf/components/spiffs/include -IC:/Users/Admin/esp-idf/components/ulp/include -IC:/Users/Admin/esp-idf/components/unity/include -IC:/Users/Admin/esp-idf/components/unity/unity/src -IC:/Users/Admin/esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -std=gnu++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -DIDF_VER=\"v4.0-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\main.cpp.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -c ../main/main.cpp
../main/main.cpp: In function 'void app_main()':
../main/main.cpp:25:18: error: invalid conversion from 'int' to 'gpio_num_t' [-fpermissive]
shiftA.begin(18,19,21,1);
^~
In file included from ../main/main.cpp:17:
../main/ShiftR.h:41:31: note: initializing argument 1 of 'void ShiftR::begin(gpio_num_t, gpio_num_t, gpio_num_t, uint8_t)'
void begin(gpio_num_t latch, gpio_num_t clk, gpio_num_t data, uint8_t n);
~~~~~~~~~~~^~~~~
../main/main.cpp:25:21: error: invalid conversion from 'int' to 'gpio_num_t' [-fpermissive]
shiftA.begin(18,19,21,1);
^~
In file included from ../main/main.cpp:17:
../main/ShiftR.h:41:49: note: initializing argument 2 of 'void ShiftR::begin(gpio_num_t, gpio_num_t, gpio_num_t, uint8_t)'
void begin(gpio_num_t latch, gpio_num_t clk, gpio_num_t data, uint8_t n);
~~~~~~~~~~~^~~
../main/main.cpp:25:24: error: invalid conversion from 'int' to 'gpio_num_t' [-fpermissive]
shiftA.begin(18,19,21,1);
^~
In file included from ../main/main.cpp:17:
../main/ShiftR.h:41:65: note: initializing argument 3 of 'void ShiftR::begin(gpio_num_t, gpio_num_t, gpio_num_t, uint8_t)'
void begin(gpio_num_t latch, gpio_num_t clk, gpio_num_t data, uint8_t n);
~~~~~~~~~~~^~~~
ninja: build stopped: subcommand failed.