Skip to content

Commit

Permalink
new: Add initial support to ESP32 RMT TX
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Feb 24, 2024
1 parent 18a58d3 commit dec4aa2
Show file tree
Hide file tree
Showing 37 changed files with 420 additions and 182 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.2
DATE=240210
DATE=240224
VERSION_STABLE=0.9.1
14 changes: 6 additions & 8 deletions src/boards/board_C3_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ cboard_C3_DevKitC::cboard_C3_DevKitC(void) {
master_uart[2].rx_pin = 0;

bitbang_pwm_init(&pwm_out, this, 6);
bitbang_out_init(&rmt_out, this, 2);

PICSimLab.UpdateGUI(MIPS, GT_COMBO, GA_ADD, (void*)"Qemu CPU MIPS");
buffer[0] = ',';
Expand All @@ -271,6 +272,7 @@ cboard_C3_DevKitC::~cboard_C3_DevKitC(void) {
PICSimLab.UpdateGUI(CONFIG, GT_BUTTON, GA_DEL, NULL);
PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWDESTROY, NULL);
bitbang_pwm_end(&pwm_out);
bitbang_out_end(&rmt_out);
}

// Reset board status
Expand Down Expand Up @@ -669,8 +671,7 @@ void cboard_C3_DevKitC::board_ButtonEvent(const char* controlname, unsigned int
"boards"
"/" BOARD_C3_DevKitC_Name +
"/config.lxrad";

if (lxFileExists(fname)) {
if (PICSimLab.SystemCmd(PSC_FILEEXISTS, fname.c_str())) {
if (PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWLOADXML, fname.c_str())) {
char buff[2048];
char line[1024];
Expand Down Expand Up @@ -930,16 +931,13 @@ void cboard_C3_DevKitC::PinsExtraConfig(int cfg) {
case 48: // ledc_ls_sig_out3
case 49: // ledc_ls_sig_out4
case 50: // ledc_ls_sig_out5
// printf("LEDC channel
// %i in GPIO %i\n",
// function - 45, gpio);
// printf("LEDC channel %i in GPIO %i\n", function - 45, gpio);
pwm_out.pins[function - 45] = io2pin(gpio);
break;
case 51: // rmt_sig_out0
case 52: // rmt_sig_out1
// printf("RMT channel
// %i in GPIO %i\n",
// function - 71, gpio);
// printf("RMT channel %i in GPIO %i\n", function - 51, gpio);
rmt_out.pins[function - 51] = io2pin(gpio);
break;

case 53: // I2CEXT0_SCL
Expand Down
27 changes: 13 additions & 14 deletions src/boards/board_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ cboard_DevKitC::cboard_DevKitC(void) {
master_uart[2].rx_pin = 0;

bitbang_pwm_init(&pwm_out, this, 16);
bitbang_out_init(&rmt_out, this, 8);

PICSimLab.UpdateGUI(MIPS, GT_COMBO, GA_ADD, (void*)"Qemu CPU MIPS");
buffer[0] = ',';
Expand All @@ -332,6 +333,7 @@ cboard_DevKitC::~cboard_DevKitC(void) {
PICSimLab.UpdateGUI(CONFIG, GT_BUTTON, GA_DEL, NULL);
PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWDESTROY, NULL);
bitbang_pwm_end(&pwm_out);
bitbang_out_end(&rmt_out);
}

// Reset board status
Expand Down Expand Up @@ -728,7 +730,7 @@ void cboard_DevKitC::board_ButtonEvent(const char* controlname, unsigned int but
"/" BOARD_DevKitC_Name +
"/config.lxrad";

if (lxFileExists(fname)) {
if (PICSimLab.SystemCmd(PSC_FILEEXISTS, fname.c_str())) {
if (PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWLOADXML, fname.c_str())) {
char buff[2048];
char line[1024];
Expand Down Expand Up @@ -984,22 +986,19 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) {
case 84: // ledc_ls_sig_out5
case 85: // ledc_ls_sig_out6
case 86: // ledc_ls_sig_out7
// printf("LEDC channel
// %i in GPIO %i\n",
// function - 71, gpio);
// printf("LEDC channel %i in GPIO %i\n",function - 71, gpio);
pwm_out.pins[function - 71] = io2pin(gpio);
break;
case 87: // rmt_sig_out0
case 88: // rmt_sig_out1
case 89: // rmt_sig_out2
case 90: // rmt_sig_out3
case 91: // rmt_sig_out4
case 92: // rmt_sig_out5
case 93: // rmt_sig_out6
case 94: // rmt_sig_out7
// printf("RMT channel
// %i in GPIO %i\n",
// function - 71, gpio);
// case 88: // rmt_sig_out1 //FIXME only channel 0 enabled
// case 89: // rmt_sig_out2
// case 90: // rmt_sig_out3
// case 91: // rmt_sig_out4
// case 92: // rmt_sig_out5
// case 93: // rmt_sig_out6
// case 94: // rmt_sig_out7
// printf("RMT channel %i in GPIO %i\n", function - 87, gpio);
rmt_out.pins[function - 87] = io2pin(gpio);
break;
case 95: // I2CEXT1_SCL
master_i2c[1].scl_pin = io2pin(gpio);
Expand Down
10 changes: 6 additions & 4 deletions src/boards/board_K16F.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ cboard_K16F::cboard_K16F(void) {
rtc_pfc8563_init(&rtc, this);
ReadMaps();

snprintf(mi2c_tmp_name, 200, "%s/picsimlab-XXXXXX", (const char*)lxGetTempDir("PICSimLab").c_str());
char tname[128];
PICSimLab.SystemCmd(PSC_GETTEMPDIR, NULL, tname);
snprintf(mi2c_tmp_name, 200, "%s/picsimlab-XXXXXX", tname);
close(mkstemp(mi2c_tmp_name));
unlink(mi2c_tmp_name);
strncat(mi2c_tmp_name, ".txt", 200);
Expand All @@ -107,7 +109,7 @@ int cboard_K16F::MInit(const char* processor, const char* fname, float freq) {
char fnamem[1024];
FILE* fout;

strncpy(fnamem, (const char*)dirname(fname).c_str(), 1023);
PICSimLab.SystemCmd(PSC_DIRNAME, fname, fnamem);
strncat(fnamem, "/mdump_K16F_EEPROM.bin", 1023);

fout = fopen_UTF8(fnamem, "rb");
Expand All @@ -124,7 +126,7 @@ int cboard_K16F::MDumpMemory(const char* mfname) {
FILE* fout;
char fname[1024];

strncpy(fname, (const char*)dirname(mfname).c_str(), 1023);
PICSimLab.SystemCmd(PSC_DIRNAME, mfname, fname);
strncat(fname, "/mdump_K16F_EEPROM.bin", 1023);

fout = fopen_UTF8(fname, "wb");
Expand Down Expand Up @@ -631,7 +633,7 @@ void cboard_K16F::EvMouseButtonPress(unsigned int button, unsigned int x, unsign
},
mi2c_tmp_name);
#else
lxLaunchDefaultApplication(mi2c_tmp_name);
PICSimLab.SystemCmd(PSC_LAUNCHDEFAULAPPLICATION, mi2c_tmp_name);
#endif
} else {
printf(
Expand Down
2 changes: 0 additions & 2 deletions src/boards/board_K16F.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#ifndef BOARD_K16F_H
#define BOARD_K16F_H

#include <lxrad.h> //FIXME remove lxrad

#include "bsim_picsim.h"

#include "../devices/lcd_hd44780.h"
Expand Down
22 changes: 13 additions & 9 deletions src/boards/board_McLab2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
######################################################################## */

#include "board_McLab2.h"
#include <math.h>
#include <unistd.h>
#include "../lib/oscilloscope.h"
#include "../lib/picsimlab.h"
#include "../lib/spareparts.h"
Expand Down Expand Up @@ -139,7 +141,7 @@ cboard_McLab2::cboard_McLab2(void) {
heater_pwr = 0;
cooler_pwr = 0;

buzzer.Init();
buzzerId = PICSimLab.SystemCmd(PSC_AUDIOCHCREATE, NULL);

pot1 = 100;

Expand All @@ -154,7 +156,9 @@ cboard_McLab2::cboard_McLab2(void) {
vent[1] = PICSimLab.CanvasCmd(
{CC_LOADIMAGE, .LoadImage{(PICSimLab.GetSharePath() + "boards/Common/VT2.svg").c_str(), 1.0, 0, 0}});

snprintf(mi2c_tmp_name, 200, "%s/picsimlab-XXXXXX", (const char*)lxGetTempDir("PICSimLab").c_str());
char tname[128];
PICSimLab.SystemCmd(PSC_GETTEMPDIR, NULL, tname);
snprintf(mi2c_tmp_name, 200, "%s/picsimlab-XXXXXX", tname);
close(mkstemp(mi2c_tmp_name));
unlink(mi2c_tmp_name);
strncat(mi2c_tmp_name, ".txt", 200);
Expand All @@ -165,8 +169,8 @@ cboard_McLab2::cboard_McLab2(void) {
}

cboard_McLab2::~cboard_McLab2(void) {
buzzer.BeepStop();
buzzer.End();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTOP, (const char*)&buzzerId);
PICSimLab.SystemCmd(PSC_AUDIOCHDESTROY, (const char*)&buzzerId);
mi2c_end(&mi2c);
lcd_end(&lcd);
PICSimLab.CanvasCmd({CC_FREEBITMAP, .FreeBitmap{vent[0]}});
Expand All @@ -188,7 +192,7 @@ int cboard_McLab2::MInit(const char* processor, const char* fname, float freq) {
char fnamem[1024];
FILE* fout;

strncpy(fnamem, (const char*)dirname(fname).c_str(), 1023);
PICSimLab.SystemCmd(PSC_DIRNAME, fname, fnamem);
strncat(fnamem, "/mdump_McLab2_EEPROM.bin", 1023);

fout = fopen_UTF8(fnamem, "rb");
Expand Down Expand Up @@ -219,7 +223,7 @@ int cboard_McLab2::MDumpMemory(const char* mfname) {
FILE* fout;
char fname[1024];

strncpy(fname, (const char*)dirname(mfname).c_str(), 1023);
PICSimLab.SystemCmd(PSC_DIRNAME, mfname, fname);
strncat(fname, "/mdump_McLab2_EEPROM.bin", 1023);

fout = fopen_UTF8(fname, "wb");
Expand Down Expand Up @@ -543,11 +547,11 @@ void cboard_McLab2::Draw(void) {

if ((((pic.pins[6].oavalue - 55) / 2) > 40) && PICSimLab.GetMcuPwr()) {
if (!sound_on) {
buzzer.BeepStart();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTART, (const char*)&buzzerId);
sound_on = 1;
}
} else {
buzzer.BeepStop();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTOP, (const char*)&buzzerId);
sound_on = 0;
}

Expand Down Expand Up @@ -1046,7 +1050,7 @@ void cboard_McLab2::EvMouseButtonPress(unsigned int button, unsigned int x, unsi
},
mi2c_tmp_name);
#else
lxLaunchDefaultApplication(mi2c_tmp_name);
PICSimLab.SystemCmd(PSC_LAUNCHDEFAULAPPLICATION, mi2c_tmp_name);
#endif
} else {
printf("Error saving to file: %s \n", mi2c_tmp_name);
Expand Down
4 changes: 1 addition & 3 deletions src/boards/board_McLab2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#ifndef BOARD_McLab2_H
#define BOARD_McLab2_H

#include <lxrad.h> //FIXME remove lxrad

#include "../devices/lcd_hd44780.h"
#include "../devices/mi2c_24CXXX.h"
#include "../devices/rtc_ds1307.h"
Expand Down Expand Up @@ -71,7 +69,7 @@ class cboard_McLab2 : public bsim_picsim {
unsigned int lm3[40]; // luminosidade media display
unsigned int lm4[40]; // luminosidade media display

lxaudio buzzer;
int buzzerId;

int vent[2];

Expand Down
22 changes: 13 additions & 9 deletions src/boards/board_PICGenios.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
######################################################################## */

#include "board_PICGenios.h"
#include <math.h>
#include <unistd.h>
#include "../lib/oscilloscope.h"
#include "../lib/picsimlab.h"
#include "../lib/spareparts.h"
Expand Down Expand Up @@ -292,7 +294,7 @@ cboard_PICGenios::cboard_PICGenios(void) {
for (int i = 0; i < 20; i++)
dip[i] = 1;

buzzer.Init();
buzzerId = PICSimLab.SystemCmd(PSC_AUDIOCHCREATE, NULL);

PICSimLab.UpdateGUI(LCD_TYPE, GT_COMBO, GA_ADD, (void*)"LCD");
PICSimLab.UpdateGUI(HEATER, GT_GAUGE, GA_ADD, (void*)"Heater");
Expand All @@ -302,7 +304,9 @@ cboard_PICGenios::cboard_PICGenios(void) {
PICSimLab.UpdateGUI(LCD_TYPE, GT_COMBO, GA_SET, (void*)",hd44780 16x2,hd44780 16x4,");
PICSimLab.UpdateGUI(LCD_TYPE, GT_COMBO, GA_SET, (void*)"hd44780 16x2");

snprintf(mi2c_tmp_name, 200, "%s/picsimlab-XXXXXX", (const char*)lxGetTempDir("PICSimLab").c_str());
char tname[128];
PICSimLab.SystemCmd(PSC_GETTEMPDIR, NULL, tname);
snprintf(mi2c_tmp_name, 200, "%s/picsimlab-XXXXXX", tname);
close(mkstemp(mi2c_tmp_name));
unlink(mi2c_tmp_name);
strncat(mi2c_tmp_name, ".txt", 200);
Expand All @@ -313,8 +317,8 @@ cboard_PICGenios::cboard_PICGenios(void) {
}

cboard_PICGenios::~cboard_PICGenios(void) {
buzzer.BeepStop();
buzzer.End();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTOP, (const char*)&buzzerId);
PICSimLab.SystemCmd(PSC_AUDIOCHDESTROY, (const char*)&buzzerId);
PICSimLab.CanvasCmd({CC_FREEBITMAP, .FreeBitmap{vent[0]}});
PICSimLab.CanvasCmd({CC_FREEBITMAP, .FreeBitmap{vent[1]}});
vent[0] = -1;
Expand Down Expand Up @@ -344,7 +348,7 @@ int cboard_PICGenios::MInit(const char* processor, const char* fname, float freq
char fnamem[1024];
FILE* fout;

strncpy(fnamem, (const char*)dirname(fname).c_str(), 1023);
PICSimLab.SystemCmd(PSC_DIRNAME, fname, fnamem);
strncat(fnamem, "/mdump_PICGenios_EEPROM.bin", 1023);

fout = fopen_UTF8(fnamem, "rb");
Expand Down Expand Up @@ -382,7 +386,7 @@ int cboard_PICGenios::MDumpMemory(const char* mfname) {
FILE* fout;
char fname[1024];

strncpy(fname, (const char*)dirname(mfname).c_str(), 1023);
PICSimLab.SystemCmd(PSC_DIRNAME, mfname, fname);
strncat(fname, "/mdump_PICGenios_EEPROM.bin", 1023);

fout = fopen_UTF8(fname, "wb");
Expand Down Expand Up @@ -852,11 +856,11 @@ void cboard_PICGenios::Draw(void) {
// buzzer
if ((((pic.pins[PIN_RC1 - 1].oavalue - 55) / 2) > 10) && (PICSimLab.GetMcuPwr()) && jmp[0]) {
if (!sound_on) {
buzzer.BeepStart();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTART, (const char*)&buzzerId);
sound_on = 1;
}
} else {
buzzer.BeepStop();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTOP, (const char*)&buzzerId);
sound_on = 0;
}

Expand Down Expand Up @@ -1754,7 +1758,7 @@ void cboard_PICGenios::EvMouseButtonPress(unsigned int button, unsigned int x, u
},
mi2c_tmp_name);
#else
lxLaunchDefaultApplication(mi2c_tmp_name);
PICSimLab.SystemCmd(PSC_LAUNCHDEFAULAPPLICATION, mi2c_tmp_name);
#endif
} else {
printf(
Expand Down
4 changes: 1 addition & 3 deletions src/boards/board_PICGenios.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#ifndef BOARD_PICGenios_H
#define BOARD_PICGenios_H

#include <lxrad.h> //FIXME remove lxrad

#include "../devices/lcd_hd44780.h"
#include "../devices/mi2c_24CXXX.h"
#include "../devices/rtc_ds1307.h"
Expand Down Expand Up @@ -80,7 +78,7 @@ class cboard_PICGenios : public bsim_picsim {
int vent[2];
int lcdbmp[2];

lxaudio buzzer;
int buzzerId;

char mi2c_tmp_name[200];

Expand Down
10 changes: 5 additions & 5 deletions src/boards/board_PQDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cboard_PQDB::cboard_PQDB(void) {

ReadMaps();

buzzer.Init();
buzzerId = PICSimLab.SystemCmd(PSC_AUDIOCHCREATE, NULL);

scroll1_old = 255; // force updated
scroll2_old = 255;
Expand All @@ -195,8 +195,8 @@ cboard_PQDB::cboard_PQDB(void) {
}

cboard_PQDB::~cboard_PQDB(void) {
buzzer.BeepStop();
buzzer.End();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTOP, (const char*)&buzzerId);
PICSimLab.SystemCmd(PSC_AUDIOCHDESTROY, (const char*)&buzzerId);

PICSimLab.UpdateGUI(TEMP, GT_SCROLL, GA_DEL, NULL);
PICSimLab.UpdateGUI(LIGHT, GT_SCROLL, GA_DEL, NULL);
Expand Down Expand Up @@ -468,11 +468,11 @@ void cboard_PQDB::Draw(void) {

if (((0.5 * (pic.pins[PWM_PIN].oavalue - 55)) > 10) && (PICSimLab.GetMcuPwr())) {
if (!sound_on) {
buzzer.BeepStart();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTART, (const char*)&buzzerId);
sound_on = 1;
}
} else {
buzzer.BeepStop();
PICSimLab.SystemCmd(PSC_AUDIOCHBEEPSTOP, (const char*)&buzzerId);
sound_on = 0;
}

Expand Down
Loading

0 comments on commit dec4aa2

Please sign in to comment.