Add C++ support to Makefile, and proof-of-concept simple.cpp example
This is a work in progress based on @mikejac's work. Missing: * No 'new' operator. * I don't think STL is currently supported.
This commit is contained in:
parent
c5bd46dae0
commit
430d0fbcbc
5 changed files with 92 additions and 3 deletions
examples/simple_cplusplus
3
examples/simple_cplusplus/Makefile
Normal file
3
examples/simple_cplusplus/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Simple makefile for simple example
|
||||
PROGRAM=simple
|
||||
include ../../common.mk
|
52
examples/simple_cplusplus/simple.cpp
Normal file
52
examples/simple_cplusplus/simple.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* A very basic C++ example, really just proof of concept for C++
|
||||
|
||||
This sample code is in the public domain.
|
||||
*/
|
||||
#include "espressif/esp_common.h"
|
||||
#include "espressif/sdk_private.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
|
||||
class Counter
|
||||
{
|
||||
private:
|
||||
uint32_t _count;
|
||||
public:
|
||||
Counter(uint32_t initial_count)
|
||||
{
|
||||
this->_count = initial_count;
|
||||
printf("Counter initialised with count %ld\r\n", initial_count);
|
||||
}
|
||||
|
||||
void Increment()
|
||||
{
|
||||
_count++;
|
||||
}
|
||||
|
||||
uint32_t getCount()
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
};
|
||||
|
||||
static Counter static_counter(99);
|
||||
|
||||
void task1(void *pvParameters)
|
||||
{
|
||||
Counter local_counter = Counter(12);
|
||||
while(1) {
|
||||
Counter &counter = rand() % 2 ? static_counter : local_counter;
|
||||
counter.Increment();
|
||||
printf("local counter %ld static counter %ld\r\n", local_counter.getCount(),
|
||||
static_counter.getCount());
|
||||
vTaskDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void user_init(void)
|
||||
{
|
||||
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
xTaskCreate(task1, (signed char *)"tsk1", 256, NULL, 2, NULL);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue