Skip to content

Commit

Permalink
snek/grove: Add port for Seeed's Grove Beginner Kit
Browse files Browse the repository at this point in the history
This supports many of the devices supplied in this kit, including:

 1. LED
 2. Buzzer (with tone function)
 3. Light sensor
 4. Sound sensor
 5. Button
 6. Rotary Potentiometer
 7. Air Pressure
 8. 3-Axis Acceleration

Still to add:

 1. OLED display
 2. Temperature and Humidity

Of course, the ROM is full at this point, so adding these presents a
significant challenge.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Feb 2, 2021
1 parent 0ae9d79 commit 846d970
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ports/grove/.gitignore
@@ -0,0 +1,4 @@
snek-grove-*.elf
snek-grove-*.hex
snek-grove-*.map
snek-grove-install
86 changes: 86 additions & 0 deletions ports/grove/Makefile
@@ -0,0 +1,86 @@
#
# Copyright © 2020 Keith Packard <keithp@keithp.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#

SNEK_ROOT = ../..
SNEK_ATMEGA = $(SNEK_ROOT)/chips/atmega
SNEK_NO_DICT = 1
SNEK_NO_SLICE = 1

include $(SNEK_ATMEGA)/snek-atmega.defs

SNEK_LOCAL_VPATH = $(SNEK_ATMEGA)

SNEK_LOCAL_SRC = \
snek-pow.c \
snek-328p.c \
snek-atmega-i2c.c \
snek-bmp280.c \
snek-lis3dh.c \
$(SNEK_ATMEGA_SRC)

SNEK_LOCAL_INC = \
$(SNEK_ATMEGA_INC)

SNEK_LOCAL_BUILTINS = \
$(SNEK_ATMEGA_BUILTINS) \
snek-328p.builtin \
snek-grove.builtin

include $(SNEK_ROOT)/snek-install.defs

SNEK_CFLAGS = $(SNEK_MOST_WARNINGS) $(SNEK_BASE_CFLAGS) -DUART_BAUD=115200

BASE=snek-grove-$(SNEK_VERSION)
ELF=$(BASE).elf
HEX=$(BASE).hex
MAP=$(BASE).map
CC=avr-gcc

OPT=-Os -frename-registers -funsigned-char -fno-jump-tables -mcall-prologues

CFLAGS=$(OPT) -DF_CPU=16000000UL -mmcu=atmega328p -I. -I$(SNEK_LOCAL_VPATH) -g $(SNEK_CFLAGS) -Waddr-space-convert
LDFLAGS=$(SNEK_LDFLAGS) \
-Wl,-uvfprintf -lprintf_flt -lm \
-Wl,--defsym -Wl,__TEXT_REGION_LENGTH__=0x7e00 \
-Wl,--defsym -Wl,__DATA_REGION_ORIGIN__=0x800100 \
-Wl,--defsym -Wl,__DATA_REGION_LENGTH__=0x780 \
-Wl,--defsym -Wl,__EEPROM_REGION_LENGTH__=0x400 \
-Wl,-Map=$(MAP)

all: $(HEX) snek-grove-install

$(HEX): $(ELF)
avr-objcopy -O ihex -R .eeprom $^ $@

$(ELF): $(SNEK_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@gawk '/__data_load_end/{printf("ROM used: %d bytes\n", strtonum($$1)); }' $(MAP)

snek-grove-install: snek-grove-install.in
$(SNEK_SED) $^ > $@
chmod +x $@

load: $(HEX) snek-grove-install
./snek-grove-install -hex $(HEX)

install: snek-grove-install $(HEX) snek-grove-install.1
install -d $(DESTDIR)$(BINDIR)
install snek-grove-install $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(SHAREDIR)
install -m 0644 $(HEX) $(DESTDIR)$(SHAREDIR)
install -d $(DESTDIR)$(MANDIR)/man1
install -m 0644 snek-grove-install.1 $(DESTDIR)$(MANDIR)/man1

clean::
rm -f snek*.elf snek*.hex snek*.map snek-grove-install
54 changes: 54 additions & 0 deletions ports/grove/snek-grove-install.1
@@ -0,0 +1,54 @@
.\"
.\" Copyright © 2020 Keith Packard <keithp@keithp.com>
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
.\" General Public License for more details.
.\"
.TH SNEK-MEGA-INSTALL 1 "snek-uno-install" ""
.SH NAME
snek-uno-install \- Install Snek to Arduino Uno
.SH SYNOPSIS
.B "snek-uno-install" [OPTION]... [COMMAND]
.SH DESCRIPTION
.I snek-uno-install
installs the Snek programming language on an ATmega328P Arduino Uno
board, including the ability to re-program the ATmega16u2 chip used as
a usbserial converter.
.SH OPTIONS
.TP
\-port <port>
Specifies the serial port to use when programming the ATmega328p chip,
the default is '/dev/ttyACM0'.
.TP
\-isp <ISP model>
Specifies the programmer to use when programming the ATmega16u2 chip
used as a usb to serial converter, common options are 'usbtiny'
and 'avrisp2'. The default is 'usbtiny'.
.TP
\-hex <snek.hex>
Specifies the hex file to load to the board. The default is the
currently installed version of Snek when programming the ATmega328p, and the
currently installed version of the usbserial program when programming
the ATmega16u2.
.SH COMMANDS
.TP
snek
Loads Snek to the target device. This is the default command. Note
that snekde will not be able to get/put programs to the device without
also reprogramming the ATmega16u2 device used as a usb to serial
converter on the Arduino Uno board.
.TP
usbserial
Loads the updated usbserial converter firmware to the ATmega16u2
device on the Arduino Uno board. This version supports the XON/XOFF
flow control required for SnekDE to be able to successfully
communicate with Snek running on the ATmega328p processor.
.SH AUTHOR
Keith Packard
37 changes: 37 additions & 0 deletions ports/grove/snek-grove-install.in
@@ -0,0 +1,37 @@
#!/bin/sh

SHAREDIR="@SHAREDIR@"

HEX="@SHAREDIR@/snek-grove-@SNEK_VERSION@.hex"
PORT=/dev/ttyUSB0

mode=arg

for i in "$@"; do
case "$mode" in
arg)
case "$i" in
-port|--port)
mode=port
;;
-hex|--hex)
mode=hex
;;
*)
echo "Usage: $0 {-port $PORT} {-hex snek-grove.hex}" 1>&2
exit 1
;;
esac
;;
port)
PORT="$i"
mode=arg
;;
hex)
HEX="$i"
mode=arg
;;
esac
done

avrdude -pATMEGA328P -carduino -P$PORT -b115200 -D -U flash:w:"${HEX}":i
18 changes: 18 additions & 0 deletions ports/grove/snek-grove.builtin
@@ -0,0 +1,18 @@
#
# Copyright © 2019 Keith Packard <keithp@keithp.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
A6, -2, 20
accel, 0
baro, 0
tone, 1
#define SNEK_TONE
1 change: 1 addition & 0 deletions snek-install.defs
Expand Up @@ -25,6 +25,7 @@ FIRMWARE ?= \
$(SNEK_PORTS)/crickit/snek-crickit-$(SNEK_VERSION).uf2 \
$(SNEK_PORTS)/duemilanove/snek-duemilanove-$(SNEK_VERSION).hex \
$(SNEK_PORTS)/feather/snek-feather-$(SNEK_VERSION).uf2 \
$(SNEK_PORTS)/grove/snek-grove-$(SNEK_VERSION).hex \
$(SNEK_PORTS)/itsybitsy3v/snek-itsybitsy3v-$(SNEK_VERSION).hex \
$(SNEK_PORTS)/itsybitsy5v/snek-itsybitsy5v-$(SNEK_VERSION).hex \
$(SNEK_PORTS)/itsybitsym0/snek-itsybitsym0-$(SNEK_VERSION).uf2 \
Expand Down

0 comments on commit 846d970

Please sign in to comment.