Skip to content

Commit

Permalink
dac108 driver working
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed May 7, 2024
1 parent 7027d29 commit 7a2d6fb
Show file tree
Hide file tree
Showing 29 changed files with 579 additions and 1,153 deletions.
32 changes: 23 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ FENNEL=fennel
BIN = $(TARGET).bin

DEFS = -DUSE_STDPERIPH_DRIVER -DSTM32F7XX -DARM_MATH_CM7 -DHSE_VALUE=8000000
DEFS += -DSTM32F722xx -DUSE_HAL_DRIVER
STARTUP = $(CUBE)/CMSIS/Device/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f722xx.s
DEFS += -DSTM32F767xx -DUSE_HAL_DRIVER
STARTUP = $(CUBE)/CMSIS/Device/ST/STM32F7xx/Source/Templates/gcc/startup_stm32f767xx.s

MCFLAGS = -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16
# MCFLAGS = -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16
MCFLAGS = -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv5-d16

STM32_INCLUDES = \
-I$(WRLIB)/ \
Expand Down Expand Up @@ -93,13 +94,26 @@ SRC = main.c \
$(HALS)/stm32f7xx_hal_pwr.c \
$(HALS)/stm32f7xx_hal_pwr_ex.c \
$(HALS)/stm32f7xx_hal_rng.c \
$(HALS)/stm32f7xx_hal_sai.c \
$(HALS)/stm32f7xx_hal_spi.c \
$(HALS)/stm32f7xx_hal_tim.c \
$(HALS)/stm32f7xx_hal_tim_ex.c \
$(HALS)/stm32f7xx_hal_uart.c \
$(HALS)/stm32f7xx_hal_usart.c \
$(HALS)/stm32f7xx_ll_usb.c \
$(wildcard lib/*.c) \
lib/ashapes.c \
lib/bootloader.c \
lib/casl.c \
lib/caw.c \
lib/clock_ll.c \
lib/detect.c \
lib/events.c \
lib/flash.c \
lib/ftrack.c \
lib/io.c \
lib/metro.c \
lib/shapes.c \
lib/slopes.c \
$(wildcard ll/*.c) \
$(wildcard usbd/*.c) \
$(USBD)/Core/Src/usbd_core.c \
Expand Down Expand Up @@ -176,10 +190,10 @@ LUALIB_OBJS= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
# build the objects from c source
OBJDIR = .
OBJS = $(SRC:%.c=$(OBJDIR)/%.o)
OBJS += $(addprefix $(LUAS)/,$(LUACORE_OBJS) $(LUALIB_OBJS) )
# OBJS += $(addprefix $(LUAS)/,$(LUACORE_OBJS) $(LUALIB_OBJS) )
OBJS += Startup.o

$(OBJS): $(LUA_PP)
# $(OBJS): $(LUA_PP)

# specific objects that require built dependencies (ii)
$(OBJDIR)/lib/l_bootstrap.o: $(LUA_PP) #$(BUILD_DIR)/ii_lualink.h
Expand Down Expand Up @@ -236,14 +250,14 @@ $(BIN): $(EXECUTABLE)
# 512kb -64kb(bootloader) -128kb(scripts)

flash: $(BIN)
st-flash write $(BIN) 0x08020000
st-flash write $(BIN) 0x08000000

debug:
make flash TRACE=1
stlink-trace -c 216

dfu: $(BIN)
sudo dfu-util -a 0 -s 0x08020000 -R -D $(BIN) -d ,0483:df11
sudo dfu-util -a 0 -s 0x08000000 -R -D $(BIN) -d ,0483:df11

dfureset:
@stty -F /dev/ttyACM0 raw speed 115200
Expand All @@ -254,7 +268,7 @@ pydfu: $(TARGET).dfu $(BIN)
@python3 util/pydfu.py -u $<

$(TARGET).dfu: $(BIN)
python3 util/dfu.py -D 0x0483:0xDF11 -b 0x08020000:$^ $@
python3 util/dfu.py -D 0x0483:0xDF11 -b 0x08000000:$^ $@

boot:
cd $(BOOTLOADER) && \
Expand Down
Binary file added crow.dfu
Binary file not shown.
44 changes: 27 additions & 17 deletions lib/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdio.h>
#include "stm32f7xx_hal.h" // HAL_Delay()

#include "../ll/adda.h" // _Init(), _Start(), _GetADCValue(), IO_block_t
// #include "../ll/adda.h" // _Init(), _Start(), _GetADCValue(), IO_block_t
#include "slopes.h" // S_init(), S_step_v()
#include "ashapes.h" // AShaper_init(), AShaper_v()
#include "detect.h" // Detect_init(), Detect(), Detect_ix_to_p()
Expand Down Expand Up @@ -37,25 +37,35 @@ void IO_Start( void )
}

// DSP process
static float saw = 0.f;
IO_block_t* IO_BlockProcess( IO_block_t* b )
{
for( int j=0; j<IN_CHANNELS; j++ ){
Detect_t* d = Detect_ix_to_p(j);
(*d->modefn)( d, b->in[j][b->size-1] );
}
for( int j=0; j<SLOPE_CHANNELS; j++ ){
S_step_v( j
, b->out[j]
, b->size
);
}
for( int j=0; j<SLOPE_CHANNELS; j++ ){
AShaper_v( j
, b->out[j]
, b->size
);
// for( int j=0; j<IN_CHANNELS; j++ ){
// Detect_t* d = Detect_ix_to_p(j);
// (*d->modefn)( d, b->in[j][b->size-1] );
// }
// for( int j=0; j<SLOPE_CHANNELS; j++ ){
// S_step_v( j
// , b->out[j]
// , b->size
// );
// }
// for( int j=0; j<SLOPE_CHANNELS; j++ ){
// AShaper_v( j
// , b->out[j]
// , b->size
// );
// }

saw += 0.001f;
saw = (saw > 1.f) ? saw - 1.f : saw;
for(int i=0; i<SLOPE_CHANNELS; i++){
for(int s=0; s<(b->size); s++){
b->out[i][s] = saw;
}
}
public_update();

// public_update();
return b;
}
float IO_GetADC( uint8_t channel )
Expand Down
3 changes: 3 additions & 0 deletions lib/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
#include <stm32f7xx.h>
#include <stdbool.h>

#include "../ll/adda.h" // _Init(), _Start(), _GetADCValue(), IO_block_t

void IO_Init( int adc_timer_ix );
void IO_Start( void );

void IO_Process( void );
IO_block_t* IO_BlockProcess( IO_block_t* b );

float IO_GetADC( uint8_t channel );
void IO_SetADCaction( uint8_t channel, const char* mode );
Expand Down
3 changes: 3 additions & 0 deletions lib/repl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "repl.h"

/*
#include <stdlib.h> // malloc(), free()
#include <string.h> // memcpy()
#include <stdbool.h>
Expand Down Expand Up @@ -219,3 +220,5 @@ static char* REPL_script_name_from_mem( char* dest, char* src, int max_len )
dest[len] = '\0';
return dest;
}
*/
6 changes: 3 additions & 3 deletions lib/repl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <stm32f7xx.h>

// lua_State*
#include "../submodules/lua/src/lua.h"
#include "../submodules/lua/src/lauxlib.h"
#include "../submodules/lua/src/lualib.h"
// #include "../submodules/lua/src/lua.h"
// #include "../submodules/lua/src/lauxlib.h"
// #include "../submodules/lua/src/lualib.h"

#include "lualink.h" // ErrorHandler_t, Lua_eval(), Lua_load_default_script()

Expand Down
2 changes: 1 addition & 1 deletion lib/slopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct{
float shaped; // current shaped output voltage
} Slope_t;

#define SLOPE_CHANNELS 4
#define SLOPE_CHANNELS 8

// refactor for dynamic SLOPE_CHANNELS
// refactor for dynamic SAMPLE_RATE
Expand Down
72 changes: 32 additions & 40 deletions ll/adda.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <stdio.h>

#include "debug_pin.h"
#include "ads131.h"
#include "dac8565.h"
// #include "ads131.h"
// #include "dac8565.h"
#include "dac108.h"

#include "../lib/flash.h" // FLASH_*_t
#include "cal_ll.h" // CAL_LL_Init(),
Expand All @@ -19,7 +20,7 @@ typedef struct {

typedef struct {
CAL_chan_t adc[2];
CAL_chan_t dac[4];
CAL_chan_t dac[8];
} CAL_t;

static CAL_t cal;
Expand All @@ -28,48 +29,44 @@ static void CAL_ReadFlash( void );

uint16_t ADDA_Init( int adc_timer_ix )
{
ADC_Init( ADDA_BLOCK_SIZE
, ADDA_ADC_CHAN_COUNT
, adc_timer_ix
);
// ADC_Init( ADDA_BLOCK_SIZE
// , ADDA_ADC_CHAN_COUNT
// , adc_timer_ix
// );
DAC_Init( ADDA_BLOCK_SIZE
, ADDA_DAC_CHAN_COUNT
);
CAL_LL_Init();
CAL_ReadFlash();
// CAL_LL_Init();
// CAL_ReadFlash();
return ADDA_BLOCK_SIZE;
}

void ADDA_Start( void )
{
void ADDA_Start( void ){
DAC_Start();
}

void ADDA_BlockProcess( uint32_t* dac_pickle_ptr )
{
IO_block_t b = { .size = ADDA_BLOCK_SIZE };
ADC_UnpickleBlock( b.in[0]
, ADDA_BLOCK_SIZE
);
static IO_block_t b = { .size = ADDA_BLOCK_SIZE };
void ADDA_BlockProcess( uint32_t* dac_pickle_ptr ){
// ADC_UnpickleBlock( b.in[0]
// , ADDA_BLOCK_SIZE
// );
IO_BlockProcess( &b );
DAC_PickleBlock( dac_pickle_ptr
, b.out[0]
, ADDA_BLOCK_SIZE
);
}

float ADDA_GetADCValue( uint8_t channel )
{
return ADC_GetValue( channel );
float ADDA_GetADCValue( uint8_t channel ){
return 0.f;
// return ADC_GetValue( channel );
}

__weak IO_block_t* IO_BlockProcess( IO_block_t* b )
{
__weak IO_block_t* IO_BlockProcess( IO_block_t* b ){
for( uint16_t i=0; i<(b->size); i++ ){
b->out[0][i] = b->in[0][i];
b->out[1][i] = b->in[1][i];
b->out[2][i] = 2.0;
b->out[3][i] = 3.0;
for(int j=0; j<8; j++){
b->out[j][i] = 0.0;
}
}
return b;
}
Expand All @@ -78,8 +75,7 @@ __weak IO_block_t* IO_BlockProcess( IO_block_t* b )
////////////////////////////////////////////
// Calibration

void CAL_WriteFlash( void )
{
void CAL_WriteFlash( void ){
if( Flash_write_calibration( (uint8_t*)(&cal)
, sizeof(CAL_chan_t) * (2+4)
) ){
Expand All @@ -93,15 +89,14 @@ void CAL_WriteFlash( void )
}
}

void CAL_Set( int chan, CAL_Param_t param, float val )
{
void CAL_Set( int chan, CAL_Param_t param, float val ){
if(chan >= 1 && chan <= 2){ // adc
if(param == CAL_Offset){
cal.adc[chan-1].shift = val;
ADC_CalibrateShift(chan-1, val);
// ADC_CalibrateShift(chan-1, val);
} else {
cal.adc[chan-1].scale = val;
ADC_CalibrateScalar(chan-1, val);
// ADC_CalibrateScalar(chan-1, val);
}
} else if( chan >= 3 && chan <= 6){ // dac
if(param == CAL_Offset){
Expand All @@ -114,8 +109,7 @@ void CAL_Set( int chan, CAL_Param_t param, float val )
}
}

float CAL_Get( int chan, CAL_Param_t param )
{
float CAL_Get( int chan, CAL_Param_t param ){
if(chan >= 1 && chan <= 2){ // adc
if(param == CAL_Offset){
return cal.adc[chan-1].shift;
Expand All @@ -131,22 +125,20 @@ float CAL_Get( int chan, CAL_Param_t param )
} else { return 0.0; }
}

static void CAL_Defaults( void )
{
static void CAL_Defaults( void ){
for( int j=1; j<7; j++ ){
CAL_Set(j, CAL_Offset, 0.0);
CAL_Set(j, CAL_Scale, 1.0);
}
}

static void CAL_ReadFlash( void )
{
static void CAL_ReadFlash( void ){
if( !Flash_read_calibration( (uint8_t*)(&cal)
, sizeof(CAL_chan_t) * (2+4)
) ){
for( int j=0; j<2; j++ ){
ADC_CalibrateShift( j, cal.adc[j].shift );
ADC_CalibrateScalar( j, cal.adc[j].scale );
// ADC_CalibrateShift( j, cal.adc[j].shift );
// ADC_CalibrateScalar( j, cal.adc[j].scale );
}
for( int j=0; j<4; j++ ){
DAC_CalibrateOffset( j, cal.dac[j].shift );
Expand Down
4 changes: 2 additions & 2 deletions ll/adda.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <stm32f7xx.h>

#define ADDA_BLOCK_SIZE 32
#define ADDA_DAC_CHAN_COUNT 4
#define ADDA_BLOCK_SIZE 2 // 32
#define ADDA_DAC_CHAN_COUNT 8
#define ADDA_ADC_CHAN_COUNT 2

typedef struct{
Expand Down
Loading

0 comments on commit 7a2d6fb

Please sign in to comment.