Skip to content

Commit

Permalink
feat: bootsrap code [#2]
Browse files Browse the repository at this point in the history
  • Loading branch information
b4nst authored Aug 18, 2023
1 parent 961971f commit 2a5282e
Show file tree
Hide file tree
Showing 13 changed files with 637 additions and 246 deletions.
366 changes: 366 additions & 0 deletions .clang-tidy

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Build and Test

on:
push:
branches:
- '**'
tags-ignore:
- v**

Expand All @@ -10,8 +12,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- name: build
run: make
- name: test
run: test -f build/polyboard.syx
- name: lint
run: make lint
- name: tidy
run: make tidy
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: carlosperate/arm-none-eabi-gcc-action@v1
- name: build
run: make
Expand Down
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,60 @@ tools/osx/simulator.xcodeproj/xcuserdata/davehodder.xcuserdatad/xcschemes/xcsche

*.xcbkptlist
tools/osx/simulator.xcodeproj/xcuserdata
# Created by https://www.toptal.com/developers/gitignore/api/vim,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# End of https://www.toptal.com/developers/gitignore/api/vim,macos
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ BUILDDIR = build

TOOLS = tools

SOURCES += src/app.c
SOURCES := $(wildcard src/*.c)
HEADERS := $(wildcard include/*.h)

INCLUDES += -Iinclude -I

Expand All @@ -23,6 +24,7 @@ HOST_GCC = gcc
CC = arm-none-eabi-gcc
LD = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
CODE_STYLE = llvm

CFLAGS = -Os -Wall -I.\
-D_STM32F103RBT6_ -D_STM3x_ -D_STM32x_ -mthumb -mcpu=cortex-m3 \
Expand Down Expand Up @@ -63,5 +65,17 @@ $(BUILDDIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) -c $(CFLAGS) -MMD -o $@ $<

fmt: $(SOURCES) $(HEADERS)
clang-format --style=$(CODE_STYLE) -i $^
.PHONY: fmt

tidy: $(SOURCES) $(HEADERS)
clang-tidy $^ -- -Iinclude
.PHONY: tidy

lint: $(SOURCES) $(HEADERS)
clang-format --style=$(CODE_STYLE) -Werror --dry-run $^
.PHONY: lint

clean:
rm -rf $(BUILDDIR)
Empty file added core
Empty file.
113 changes: 66 additions & 47 deletions include/app.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#ifndef LAUNCHPAD_APP_H
#define LAUNCHPAD_APP_H
#ifndef APP_H
#define APP_H

/******************************************************************************
Copyright (c) 2015, Focusrite Audio Engineering Ltd.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Focusrite Audio Engineering Ltd., nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -30,9 +30,11 @@
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

// NOLINTBEGIN

// ____________________________________________________________________________
//
// Don't modify this file! This declares the binary interface to the library,
Expand All @@ -44,13 +46,13 @@
/******************************************************************************
Button indexing is as follows - numbers in brackets do not correspond to real
buttons, but can be harmessly sent in hal_set_led.
(90)91 92 93 94 95 96 97 98 (99)
.......
20 21 22 23 24 25 26 27 28 29
10 11 12 13 14 15 16 17 18 19
(0) 1 2 3 4 5 6 7 8 (9)
*****************************************************************************/

// ____________________________________________________________________________
Expand All @@ -62,8 +64,10 @@
* Set an LED's RGB value. This function is safe to call from any
* of the app functions below, at any time.
*
* @param type - TYPEPAD to address any pad or button, TYPESETUP to address the Setup button
* @param index - The index of the button. The buttons are indexed from the bottom left as detailed above.
* @param type - TYPEPAD to address any pad or button, TYPESETUP to address the
* Setup button
* @param index - The index of the button. The buttons are indexed from the
* bottom left as detailed above.
* @param red - red colour value, in [0, MAXLED]
* @param green - green colour value, in [0, MAXLED]
* @param blue - blue colour value, in [0, MAXLED]
Expand All @@ -72,10 +76,11 @@ void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue);

/**
* Read the RGB value of an LED. This function is safe to call from any
* of the app functions below, at any time. Result is undefined if an invalid address is passed
* for any of the red, green or blue components.
* of the app functions below, at any time. Result is undefined if an invalid
* address is passed for any of the red, green or blue components.
*
* @param type - TYPEPAD to address any pad or button, TYPESETUP to address the Setup LED
* @param type - TYPEPAD to address any pad or button, TYPESETUP to address the
* Setup LED
* @param index - The index of the button, as above
* @param red - address to read red colour value, in [0, MAXLED].
* @param green - address to read green colour value, in [0, MAXLED]
Expand All @@ -85,25 +90,28 @@ void hal_read_led(u8 type, u8 index, u8 *red, u8 *green, u8 *blue);

/**
* Send a MIDI message to either USB port or to the DIN output.
*
* @param port - which port to send the message to - can be USBSTANDALONE, USBMIDI or DINMIDI.
*
* @param port - which port to send the message to - can be USBSTANDALONE,
* USBMIDI or DINMIDI.
* @param status - MIDI status byte
* @param data1 - first MIDI data byte
* @param data2 - second MIDI data byte
*
* There is little error checking in this code - if you send invalid MIDI, the results are undefined!
* There is little error checking in this code - if you send invalid MIDI, the
* results are undefined!
*/
void hal_send_midi(u8 port, u8 status, u8 data1, u8 data2);

/**
* Send system exclusive to USB or DIN. Messages must be correctly formatted
* (F0 ... F7) and must not exceed 320 bytes.
*
* @param port - which port to send the message to - can be USBSTANDALONE, USBMIDI or DINMIDI.
* @param port - which port to send the message to - can be USBSTANDALONE,
* USBMIDI or DINMIDI.
* @param data - pointer to array containing sysex data. Can be on the stack.
* @param length - must not exceed 320 bytes, behaviour undefined if it does.
*/
void hal_send_sysex(u8 port, const u8* data, u16 length);
void hal_send_sysex(u8 port, const u8 *data, u16 length);

/**
* Read some data from flash.
Expand Down Expand Up @@ -137,7 +145,7 @@ void hal_read_flash(u32 offset, u8 *data, u32 length);
*
* Attempts to write beyond the end of the block will fail silently
*/
void hal_write_flash(u32 offset,const u8 *data, u32 length);
void hal_write_flash(u32 offset, const u8 *data, u32 length);

/**
* Retrieve the device ID bootloader option
Expand All @@ -152,8 +160,9 @@ u8 hal_read_device_id();
/**
* Retrieve the "layout text" bootloader option
*
* This setting determines whether the factory firmware will scroll text on changing
* layouts. This may be useful as a preference for open firmware apps as well.
* This setting determines whether the factory firmware will scroll text on
* changing layouts. This may be useful as a preference for open firmware apps
* as well.
*
* @result 1 to scroll text on layout changes, 0 not to.
*/
Expand All @@ -167,10 +176,10 @@ u8 hal_read_layout_text();
/**
* Called on startup, this is a good place to do any initialisation.
*
* @param adc_buffer - this is a pointer to the raw ADC frame buffer. The
* data is 12 bit unsigned. Note the indexing is strange -
* translate ADC indices to LED/button indices using the
* ADC_MAP table declared in app_defs.h.
* @param adc_buffer - this is a pointer to the raw ADC frame buffer.
* The data is 12 bit unsigned. Note the indexing
*is strange - translate ADC indices to LED/button indices using the ADC_MAP
*table declared in app_defs.h.
*/
void app_init(const u16 *adc_buffer);

Expand All @@ -185,52 +194,62 @@ void app_timer_event();
/**
* Called when a MIDI message is received from USB or DIN.
*
* @param port - the port the message was received from - USBSTANDALONE, USBMIDI or DINMIDI.
* @param port - the port the message was received from - USBSTANDALONE, USBMIDI
* or DINMIDI.
* @param status - MIDI status byte
* @param data1 - first MIDI data byte
* @param data2 - second MIDI data byte
*/
void app_midi_event(u8 port, u8 status, u8 d1, u8 d2);

/**
* As above, but for system exclusive messages. Low level hardware buffering sets
* a maximum message size of 320 bytes, messages larger than this will not work.
*
* @param port - the port the message was received from - USBSTANDALONE, USBMIDI or DINMIDI.
* @param data - pointer to array containing sysex data. Only valid in the scope of this callback.
* As above, but for system exclusive messages. Low level hardware buffering
* sets a maximum message size of 320 bytes, messages larger than this will not
* work.
*
* @param port - the port the message was received from - USBSTANDALONE, USBMIDI
* or DINMIDI.
* @param data - pointer to array containing sysex data. Only valid in the
* scope of this callback.
* @param length - the amount of data received.
*/
void app_sysex_event(u8 port, u8 * data, u16 count);
void app_sysex_event(u8 port, u8 *data, u16 count);

/**
* Called when a MIDI DIN breakout cable is connected or disconnected. Note that
* you can still write MIDI events to the DIN ports even if no cable is connected.
* Called when a MIDI DIN breakout cable is connected or disconnected. Note
* that you can still write MIDI events to the DIN ports even if no cable is
* connected.
*
* @param type - which cable was connected/disconnected - MIDI_IN_CABLE or MIDI_OUT_CABLE.
* @param type - which cable was connected/disconnected - MIDI_IN_CABLE or
* MIDI_OUT_CABLE.
* @param value - 0 = disconnected, nonzero = connected.
*/
void app_cable_event(u8 type, u8 value);

/**
* Called when the user presses or releases any button or pad on the control surface.
* Called when the user presses or releases any button or pad on the control
* surface.
*
* @param type - TYPEPAD for normal pads or buttons, TYPESETUP for the Setup button
* @param index - The index of the button, as detailed at the start of this file.
* @param type - TYPEPAD for normal pads or buttons, TYPESETUP for the Setup
* button
* @param index - The index of the button, as detailed at the start of this
* file.
* @param value - 0 for release, nonzero for press.
*/
void app_surface_event(u8 type, u8 index, u8 value);

/**
* Called when the low level pad scanning reports an aftertouch (pad pressure) event.
* A pad press event will always come first. Note that the factory firmware sets a
* threshold to prevent excessive aftertouch after the initial hit, at the expense of
* dynamic range. This firmware does not - the full range of the pad is transmitted,
* with the side effect that aftertouch onset is more rapid.
* Called when the low level pad scanning reports an aftertouch (pad pressure)
* event. A pad press event will always come first. Note that the factory
* firmware sets a threshold to prevent excessive aftertouch after the initial
* hit, at the expense of dynamic range. This firmware does not - the full
* range of the pad is transmitted, with the side effect that aftertouch onset
* is more rapid.
*
* @param index - The index of the pad, as detailed at the start of this file.
* @param value - the aftertouch value in [0, 127]
*/
void app_aftertouch_event(u8 index, u8 value);


// NOLINTEND
#endif
Loading

0 comments on commit 2a5282e

Please sign in to comment.