Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ examples/.DS_Store
bitlash.o
.DS_Store
Bitlash/
.pioenvs
.piolibdeps
*~
7 changes: 7 additions & 0 deletions bitlash.cpp → bitlash.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@


***/
#ifndef ESP32

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
Expand All @@ -46,6 +48,7 @@
//#include "src/bitlash-arduino.c"
#endif


#include "src/bitlash-cmdline.c"
#include "src/bitlash-eeprom.c"
#include "src/bitlash-error.c"
Expand All @@ -58,3 +61,7 @@
#include "src/bitlash-taskmgr.c"
#include "src/bitlash-api.c"
#include "src/eeprom.c"

#endif //ifndef ESP32


17 changes: 17 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "bitlash",
"keywords": "console cli shell bitlash",
"description": "Bitlash is a tiny language interpreter that provides a serial port shell environment for bit banging and hardware hacking.",
"build": {
"flags": "",
"srcFilter": "+<*.cpp> -<examples/> -<bitlash-unix.c> -<mygetch.c>"
},
"repository":
{
"type": "git",
"url": "https://github.com/billroy/bitlash.git"
},
"frameworks": "arduino",
"platforms": "espressif32"

}
10 changes: 10 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=bitlash
version=2.1
author=Bill Roy
maintainer=Bill Roy
sentence=Bitlash is a tiny CLI.
paragraph=With builtin language interpreter that provides a serial port shell environment for bit banging and hardware hacking.
category=Other
url=bitlash.net
architectures=*

5 changes: 3 additions & 2 deletions src/bitlash-api.c → src/bitlash-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ numvar doCommand(char *cmd) {


void initBitlash(unsigned long baud) {

#if defined(TINY_BUILD)
beginSerial(9600);
#else
beginSerial(baud);
#endif

#if defined(ARM_BUILD)
eeinit();
#endif
#if defined(ESP32)
EEPROM.begin(E2END);
#endif

initTaskList();
vinit();
Expand Down
13 changes: 13 additions & 0 deletions src/bitlash-builtins.c → src/bitlash-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ const prog_char builtin_table[] PROGMEM = {
BUILT_IN("output", "return 1")
BUILT_IN("digitalread", "return dr(arg(1))")
#endif
#if defined(ESP32)
BUILT_IN("low", "return 0")
BUILT_IN("high", "return 1")
BUILT_IN("input", "return 1")
BUILT_IN("output", "return 2")
BUILT_IN("pullup", "return 4")
BUILT_IN("input_pullup","return 5")
BUILT_IN("pulldown", "return 8")
BUILT_IN("input_pulldown","return 9")
BUILT_IN("open_drain", "return 16")
BUILT_IN("output_open", "return 18")
BUILT_IN("analog", "return 12")
#endif

// This sentinel must be last
BUILT_IN("","") // guards end of table, must be last
Expand Down
6 changes: 4 additions & 2 deletions src/bitlash-cmdline.c → src/bitlash-cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ char lbuf[LBUFLEN];

// Help text
//
#if !defined(TINY_BUILD)
#if defined(ESP32)
const prog_char helptext[] PROGMEM = { "http://bitlash.net\r\nSee LICENSE for license\r\nPins: d0-39,a0-39 Variables: a-z, 32 bit long integers\r\nOperators: + - * / ( ) < <= > >= == != << >> ! ^ & | ++ -- :=\r\nCommands: \0" };
#elif !defined(TINY_BUILD)
const prog_char helptext[] PROGMEM = { "http://bitlash.net\r\nSee LICENSE for license\r\nPins: d0-22,a0-22 Variables: a-z, 32 bit long integers\r\nOperators: + - * / ( ) < <= > >= == != << >> ! ^ & | ++ -- :=\r\nCommands: \0" };
#else
const prog_char helptext[] PROGMEM = { "http://bitlash.net\r\n\0" };
Expand Down Expand Up @@ -176,7 +178,7 @@ void doCharacter(char c) {
}
#endif
#if !defined(TINY_BUILD)
else if (c == 21) { // ^U to get last line
else if (c == 21 || c == 16) { // ^U or ^P to get last line
msgpl(M_ctrlu);
prompt();
sp(lbuf);
Expand Down
3 changes: 3 additions & 0 deletions src/bitlash-eeprom.c → src/bitlash-eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ char id[IDLEN+1]; // buffer for id
eewrite(addr, 0);
}

#if defined(ESP32)
EEPROM.commit();
#endif
msgpl(M_saved);
}

Expand Down
File renamed without changes.
15 changes: 13 additions & 2 deletions src/bitlash-functions.c → src/bitlash-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
***/
#include "bitlash.h"



#ifdef ESP32

// AS Of 2017-11 no analogWrite yet
void analogWrite(byte pin, int value) { sp("analogWrite() not supported yet!");oops('!'); }
#endif

// syntactic sugar for func_handlers()
#if 0 // 15022 bytes
#define arg1 getarg(1)
Expand Down Expand Up @@ -90,6 +98,9 @@ numvar func_free(void) {
return 1000L;
#elif defined(ARM_BUILD)
return 1000L;
#elif defined(ESP32)

return (numvar)esp_get_free_heap_size();
#else
numvar ret;
// from http://forum.pololu.com/viewtopic.php?f=10&t=989&view=unread#p4218
Expand Down Expand Up @@ -487,14 +498,14 @@ bitlash_function fp;
else
#endif
// built-in function
#ifdef UNIX_BUILD
#if defined(UNIX_BUILD) or defined(ESP32)
fp = function_table[entry];
#else
fp = (bitlash_function) pgm_read_word(&function_table[entry]);
#endif

parsearglist(); // parse the arguments
numvar ret = (*fp)(); // call the function
numvar ret = (*fp)(); // call the function
releaseargblock(); // peel off the arguments
vpush(ret); // and push the return value
}
File renamed without changes.
9 changes: 7 additions & 2 deletions src/bitlash-interpreter.c → src/bitlash-interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void nukeeeprom(void) {
}


#if defined(AVR_BUILD)
#if defined(AVR_BUILD) && !defined(ESP32)
void cmd_boot(void) {
// This is recommended but does not work on Arduino
// Reset_AVR();
Expand Down Expand Up @@ -95,7 +95,12 @@ void cmd_boot(void) {
SCB_AIRCR = 0x05FA0000 | SCB_AIRCR_SYSRESETREQ_MASK;
while(1);
}
#endif
#endif // if ARM_BUILD==1
#elif defined(ESP32)

void cmd_boot(void) {esp_restart();}


#else
void cmd_boot(void) {oops('boot');}
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/bitlash-parser.c → src/bitlash-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
***/
#include "bitlash.h"

#if defined(AVR_BUILD)
#if defined(AVR_BUILD) && ! defined(ESP32)
#include "avr/eeprom.h"
#endif

Expand Down Expand Up @@ -421,7 +421,7 @@ byte pinnum(char id[]) {
// > d13=1 ... and similarly for analog pinvars like a5
//
//
//#define PIN_ALIASES 1
#define PIN_ALIASES 1

#ifdef PIN_ALIASES

Expand All @@ -430,10 +430,10 @@ byte pinnum(char id[]) {
#define PV_MASK 0x3f

const prog_char pinnames[] PROGMEM = {
"tx\0rx\0led\0vin\0zed\0"
"tx\0rx\0led\0vin\0zed\0therm1\0therm2\0"
};
const prog_uchar pinvalues[] PROGMEM = {
0, 1, 13, (PV_ANALOG | 1), (PV_VAR | 25)
0, 1, 2, (PV_ANALOG | 1), (PV_VAR | 25), (PV_ANALOG |22), (PV_ANALOG |23)
};

byte findpinname(char *alias) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/bitlash-unix.c → src/bitlash-unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#if defined (UNIX_BUILD)

#include "bitlash.h"

/*
Expand Down Expand Up @@ -365,3 +368,5 @@ int main () {
#endif

}

#endif //if defined (UNIX_BUILD)
73 changes: 63 additions & 10 deletions src/bitlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@
#ifndef _BITLASH_H
#define _BITLASH_H


#if defined(__x86_64__) || defined(__i386__)
#define UNIX_BUILD 1
#elif defined(__SAM3X8E__)
#define ARM_BUILD 1
#elif (defined(__MK20DX128__) || defined(__MK20DX256__)) && defined (CORE_TEENSY)
#elif (defined(__MK20DX128__) || defined(__MK20DX256__)) && (defined (CORE_TEENSY) || defined (TEENSYDUINO))
// Teensy 3
#define ARM_BUILD 2
#elif defined(PART_LM4F120H5QR) //support Energia.nu - Stellaris Launchpad / Tiva C Series
#define ARM_BUILD 4 //support Energia.nu - Stellaris Launchpad / Tiva C Series
#elif defined(ESP32)
#define XTENSA_BUILD 1
#else
#define AVR_BUILD 1
#endif


#if defined(AVR_BUILD)
#if defined(AVR_BUILD) && !defined(ESP32)
#include "avr/io.h"
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
Expand Down Expand Up @@ -132,8 +134,10 @@
#include "Arduino.h"
#define prog_char char PROGMEM
#define prog_uchar char PROGMEM
#include <HardwareSerial.h>
#else
#include "WProgram.h"

#include "WProgram.h"
#include "WConstants.h"
#endif

Expand Down Expand Up @@ -424,14 +428,62 @@ unsigned long millis(void);
#define strcmp_P strcmp
#define strlen_P strlen
#if ARM_BUILD==1
#define E2END 4096
#else
// Teensy 3
#define E2END 2048
#define E2END 4095
#elif ARM_BUILD==2 // Teensy 3 //
#define E2END 2047
#endif

#endif

extern void displayBanner(void);
extern void initlbuf(void);
extern void pointToError(void);
extern void cmd_function(void);
extern void eraseentry(char *id);
extern void cmd_ls(void);
extern void cmd_peep(void);
extern void cmd_help(void);
extern char find_user_function(char *id);
extern byte findbuiltin(char *name);
extern void analogWrite(byte pin, int value);
extern void oops(int errcode);

/////////////////////////////////// ESP32
//
// ESP32 BUILD
#if defined(ESP32)

#include <Arduino.h>
#include <stdint.h>
#include <setjmp.h>
#include <HardwareSerial.h>
#include <EEPROM.h>

extern void displayBanner(void);
extern void initlbuf(void);
extern void pointToError(void);
extern void cmd_function(void);
extern void eraseentry(char *id);
extern void cmd_ls(void);
extern void cmd_peep(void);
extern void cmd_help(void);
extern char find_user_function(char *id);
extern byte findbuiltin(char *name);
extern void analogWrite(byte pin, int value);
extern void oops(int errcode);


#define NUMPINS 39

#define E2END SPI_FLASH_SEC_SIZE - 1 // 4096
extern void eeinit(void);
extern void eewrite(int addr, uint8_t value);
extern uint8_t eeread(int addr);

#endif // ESP32

////////////////////////////////// ESP32 END


// numvar is 32 bits on Arduino and 16 bits elsewhere
#if (defined(ARDUINO_BUILD) || defined(UNIX_BUILD)) && !defined(TINY_BUILD)
Expand Down Expand Up @@ -519,7 +571,8 @@ int findend(int);
void eeputs(int);

#define EMPTY ((uint8_t)255)
#define STARTDB 0
#define STARTDB 0 // the space to reserve at the begining of EEPROM
//#define ENDDB (E2END - xx) // where xx is the space to reserve at the end of EEPROM
#define FAIL ((int)-1)

/////////////////////////////////////////////
Expand Down Expand Up @@ -720,7 +773,7 @@ extern numvar symval; // value of current numeric expression

#define USE_GPIORS defined(AVR_BUILD)

#ifndef GPIOR0 || GPIOR1
#if !defined(GPIOR0) || !defined(GPIOR1)
#undef USE_GPIORS
#endif
#if (defined USE_GPIORS)
Expand Down
Loading