Skip to content

Commit

Permalink
add support for ESP32-C3
Browse files Browse the repository at this point in the history
*flashing js code using uart currently does not work for the C3
  • Loading branch information
cubicap committed Jul 16, 2023
1 parent 0c54e6c commit a253705
Show file tree
Hide file tree
Showing 4 changed files with 1,903 additions and 5 deletions.
4 changes: 2 additions & 2 deletions main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ dependencies:
jac-device:
path: src
git: https://github.com/cubicap/Jaculus-dcore.git
version: v0.0.9
version: v0.0.10
simple-radio:
git: https://github.com/RoboticsBrno/Esp32-simple-radio.git
version: v1.2.0
version: v1.2.1
SmartLeds:
git: https://github.com/RoboticsBrno/SmartLeds.git
version: v3.1.2
12 changes: 9 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@
#include "esp_pthread.h"


#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
#include "util/jtagStream.h"
#endif


#if defined(CONFIG_IDF_TARGET_ESP32)
#include "platform/esp32.h"
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
#include "util/jtagStream.h"
#include "platform/esp32s3.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#include "platform/esp32c3.h"
#endif

wl_handle_t storage_wl_handle = WL_INVALID_HANDLE;
Expand Down Expand Up @@ -93,7 +99,7 @@ jac::Device<Machine> device(
using Mux_t = jac::Mux<jac::CobsEncoder>;
std::unique_ptr<Mux_t> muxUart;

#if defined(CONFIG_IDF_TARGET_ESP32S3)
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
std::unique_ptr<Mux_t> muxJtag;
#endif

Expand Down Expand Up @@ -145,7 +151,7 @@ int main() {
auto handleUart = device.router().subscribeTx(1, *muxUart);
muxUart->bindRx(std::make_unique<decltype(handleUart)>(std::move(handleUart)));

#if defined(CONFIG_IDF_TARGET_ESP32S3)
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3)
// initialize usb connection
auto jtagStream = std::make_unique<JtagStream>(4096, 1024);
jtagStream->start();
Expand Down
45 changes: 45 additions & 0 deletions main/platform/esp32c3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <jac/machine/machine.h>
#include <set>
#include <unordered_map>
#include <string>

#include "hal/adc_types.h"
#include "soc/adc_channel.h"


template<class Next>
class PlatformInfoFeature : public Next {
public:
struct PlatformInfo {
static inline const std::string NAME = "ESP32-C3";

struct PinConfig {
static inline const std::set<int> DIGITAL_PINS = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21
};
static inline const std::unordered_map<int, std::pair<int, int>> ANALOG_PINS = {
{ 0, { 1, ADC1_GPIO0_CHANNEL }},
{ 1, { 1, ADC1_GPIO1_CHANNEL }},
{ 2, { 1, ADC1_GPIO2_CHANNEL }},
{ 3, { 1, ADC1_GPIO3_CHANNEL }},
{ 4, { 1, ADC1_GPIO4_CHANNEL }}
};
static inline const std::set<int> INTERRUPT_PINS = DIGITAL_PINS;
static inline const int DEFAULT_I2C_SDA_PIN = 0;
static inline const int DEFAULT_I2C_SCL_PIN = 1;
};
};

void initialize() {
Next::initialize();

jac::ContextRef ctx = this->context();

jac::Object platformInfo = jac::Object::create(ctx);
platformInfo.defineProperty("name", jac::Value::from(ctx, PlatformInfo::NAME), jac::PropFlags::Enumerable);

ctx.getGlobalObject().defineProperty("PlatformInfo", platformInfo, jac::PropFlags::Enumerable);
}
};
Loading

0 comments on commit a253705

Please sign in to comment.