Add clang-format
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
14
.gitea/workflows/check-format.yaml
Normal file
14
.gitea/workflows/check-format.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
name: Check code formatting
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
Check-C-Format:
|
||||
runs-on: ubuntu-22.04-full
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
- name: Run clang format
|
||||
run: |
|
||||
cmake software -B build
|
||||
cmake --build build -- check-format
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ hardware/tonberry-pico/tonberry-pico-backups/
|
||||
*~
|
||||
*.kicad_sch-bak
|
||||
*.kicad_sch.lck
|
||||
software/build
|
||||
|
||||
13
software/CMakeLists.txt
Normal file
13
software/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(tonberry-pico)
|
||||
|
||||
add_custom_target(check-format
|
||||
find . -iname '*.[ch]' -exec clang-format -Werror --dry-run {} +
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
add_custom_target(clang-format
|
||||
find . -iname '*.[ch]' -exec clang-format -i {} +
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
6
software/src/.clang-format
Normal file
6
software/src/.clang-format
Normal file
@@ -0,0 +1,6 @@
|
||||
# -*- mode: yaml -*-
|
||||
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 120
|
||||
BreakBeforeBraces: WebKit # Only break at start of functions
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
#include "py/mperrno.h"
|
||||
|
||||
void core1_main(void) {
|
||||
void core1_main(void)
|
||||
{
|
||||
if (!i2s_init(shared_context.out_pin, shared_context.sideset_base, shared_context.samplerate))
|
||||
multicore_fifo_push_blocking(MP_EIO);
|
||||
|
||||
|
||||
@@ -8,20 +8,23 @@
|
||||
#include <string.h>
|
||||
|
||||
/* Access rules
|
||||
* audiocore processing runs on core 1 and, unless stated otherwise, all variables may only be accessed from core 1.
|
||||
* Take care of interrupt safety where needed.
|
||||
* The micropython interface lives in module.c and is invoked from the micropython runtime on core 0.
|
||||
* Micropython objects may only be handled in that context
|
||||
* The audiocore_shared_context struct defined below is used for communication between the cores.
|
||||
* audiocore processing runs on core 1 and, unless stated otherwise, all
|
||||
* variables may only be accessed from core 1. Take care of interrupt safety
|
||||
* where needed. The micropython interface lives in module.c and is invoked from
|
||||
* the micropython runtime on core 0. Micropython objects may only be handled in
|
||||
* that context The audiocore_shared_context struct defined below is used for
|
||||
* communication between the cores.
|
||||
*/
|
||||
|
||||
#define AUDIO_BUFFER_SIZE 2048
|
||||
|
||||
// Context shared between the micropython runtime on core0 and the audio task on core1
|
||||
// All access must hold "lock" unless otherwise noted
|
||||
// Context shared between the micropython runtime on core0 and the audio task on
|
||||
// core1 All access must hold "lock" unless otherwise noted
|
||||
struct audiocore_shared_context {
|
||||
spin_lock_t *lock;
|
||||
int out_pin, sideset_base, samplerate; // Set by module.c before core1 is launched and then never changed, can be read without lock
|
||||
int out_pin, sideset_base,
|
||||
samplerate; // Set by module.c before core1 is launched and then never
|
||||
// changed, can be read without lock
|
||||
uint32_t audio_buffer[AUDIO_BUFFER_SIZE];
|
||||
int audio_buffer_write, audio_buffer_read;
|
||||
int underruns;
|
||||
@@ -48,7 +51,8 @@ static inline unsigned audiocore_get_audio_buffer_avail(void)
|
||||
static inline void audiocore_audio_buffer_put(const uint32_t *restrict src, const size_t len)
|
||||
{
|
||||
const unsigned end_samples = AUDIO_BUFFER_SIZE - shared_context.audio_buffer_write;
|
||||
memcpy(shared_context.audio_buffer + shared_context.audio_buffer_write, src, 4 * ((end_samples >= len) ? len : end_samples));
|
||||
memcpy(shared_context.audio_buffer + shared_context.audio_buffer_write, src,
|
||||
4 * ((end_samples >= len) ? len : end_samples));
|
||||
if (end_samples < len) {
|
||||
memcpy(shared_context.audio_buffer, src + end_samples, 4 * (len - end_samples));
|
||||
shared_context.audio_buffer_write = len - end_samples;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2024 Matthias Blankertz <matthias@blankertz.org>
|
||||
|
||||
#include "i2s_max98357.pio.h"
|
||||
#include "audiocore.h"
|
||||
#include "i2s_max98357.pio.h"
|
||||
|
||||
#include <hardware/dma.h>
|
||||
#include <hardware/sync.h>
|
||||
@@ -23,7 +23,6 @@ struct i2s_context {
|
||||
|
||||
static struct i2s_context i2s_context;
|
||||
|
||||
|
||||
static void dma_isr(void)
|
||||
{
|
||||
if (!dma_channel_get_irq1_status(i2s_context.dma_ch))
|
||||
@@ -56,7 +55,8 @@ bool i2s_init(int out_pin, int sideset_base, int samplerate)
|
||||
if (i2s_context.pio_sm == -1)
|
||||
return false;
|
||||
i2s_context.pio_program_offset = pio_add_program(audiocore_pio, &i2s_max98357_program);
|
||||
i2s_max98357_program_init(audiocore_pio, i2s_context.pio_sm, i2s_context.pio_program_offset, out_pin, sideset_base, samplerate);
|
||||
i2s_max98357_program_init(audiocore_pio, i2s_context.pio_sm, i2s_context.pio_program_offset, out_pin, sideset_base,
|
||||
samplerate);
|
||||
|
||||
i2s_context.dma_ch = dma_claim_unused_channel(false);
|
||||
if (i2s_context.dma_ch == -1)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "audiocore.h"
|
||||
|
||||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
// This module is RP2 specific
|
||||
#include "mphalport.h"
|
||||
@@ -19,7 +19,8 @@ struct audiocore_Context_obj {
|
||||
mp_obj_base_t base;
|
||||
};
|
||||
|
||||
static mp_obj_t audiocore_Context_deinit(mp_obj_t self_in) {
|
||||
static mp_obj_t audiocore_Context_deinit(mp_obj_t self_in)
|
||||
{
|
||||
struct audiocore_Context_obj *self = MP_OBJ_TO_PTR(self_in);
|
||||
multicore_fifo_push_blocking(AUDIOCORE_CMD_SHUTDOWN);
|
||||
multicore_fifo_pop_blocking();
|
||||
@@ -30,7 +31,8 @@ static mp_obj_t audiocore_Context_deinit(mp_obj_t self_in) {
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(audiocore_Context_deinit_obj, audiocore_Context_deinit);
|
||||
|
||||
static mp_obj_t audiocore_Context_put(mp_obj_t self_in, mp_obj_t buffer) {
|
||||
static mp_obj_t audiocore_Context_put(mp_obj_t self_in, mp_obj_t buffer)
|
||||
{
|
||||
struct audiocore_Context_obj *self = MP_OBJ_TO_PTR(self_in);
|
||||
(void)self;
|
||||
mp_buffer_info_t bufinfo;
|
||||
@@ -50,11 +52,12 @@ static mp_obj_t audiocore_Context_put(mp_obj_t self_in, mp_obj_t buffer) {
|
||||
const unsigned underruns = shared_context.underruns;
|
||||
spin_unlock(shared_context.lock, flags);
|
||||
|
||||
mp_obj_t items[] = {mp_obj_new_int(to_copy),
|
||||
mp_obj_t items[] = {
|
||||
mp_obj_new_int(to_copy),
|
||||
mp_obj_new_int(buf_space),
|
||||
mp_obj_new_int(underruns),};
|
||||
mp_obj_new_int(underruns),
|
||||
};
|
||||
return mp_obj_new_tuple(3, items);
|
||||
//return mp_obj_new_int(to_copy);
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_2(audiocore_Context_put_obj, audiocore_Context_put);
|
||||
|
||||
@@ -66,14 +69,11 @@ static const mp_rom_map_elem_t audiocore_Context_locals_dict_table[] = {
|
||||
static MP_DEFINE_CONST_DICT(audiocore_Context_locals_dict, audiocore_Context_locals_dict_table);
|
||||
const mp_obj_type_t audiocore_Context_type;
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
audiocore_Context_type,
|
||||
MP_QSTR_Context,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
locals_dict, &audiocore_Context_locals_dict
|
||||
);
|
||||
MP_DEFINE_CONST_OBJ_TYPE(audiocore_Context_type, MP_QSTR_Context, MP_TYPE_FLAG_NONE, locals_dict,
|
||||
&audiocore_Context_locals_dict);
|
||||
|
||||
static mp_obj_t audiocore_init(mp_obj_t pin_obj, mp_obj_t sideset_obj, mp_obj_t samplerate_obj) {
|
||||
static mp_obj_t audiocore_init(mp_obj_t pin_obj, mp_obj_t sideset_obj, mp_obj_t samplerate_obj)
|
||||
{
|
||||
if (initialized)
|
||||
mp_raise_OSError(MP_EBUSY);
|
||||
if (!shared_context.lock) {
|
||||
|
||||
Reference in New Issue
Block a user