Skip to content

Commit

Permalink
hardware divider eabi library
Browse files Browse the repository at this point in the history
  • Loading branch information
ClockSelect committed Mar 17, 2021
1 parent a631da4 commit bee5e7f
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 39 deletions.
13 changes: 7 additions & 6 deletions inc/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ typedef struct display
void (*CLS)( void );
void (*SetBrightness)( uint32_t b );
void (*SetFont)( const font_t* );
void (*Print)( const char*, const rect_t* );
void (*Print)( const char*, const rect_t*, unsigned align );
}
display_t;


extern const display_t *display;


extern const display_t ST7735S;

extern DISPLAY_STATUS display_status;

extern uint16_t fgcolor;
extern uint16_t bgcolor;

extern void SetDisplay( const display_t *d );
extern void SetDisplayStatus( uint32_t status );
extern DISPLAY_STATUS GetDisplayStatus( void );

extern void DMStartup();
extern void DMSetStatus( DISPLAY_STATUS status );
extern DISPLAY_STATUS DMGetStatus();

extern void FormatNumber( char *str, uint32_t num, int nbdig, int nbdec, int exp );


#endif /* __DISPLAY_H__ */
Binary file added lib/armlib/c2_p.l
Binary file not shown.
44 changes: 44 additions & 0 deletions lib/armlib/libattrs.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# libattrs.map
#
# This file defines the mapping from library names to the
# attributes assumed for that library by the linker. It is for
# internal use only. Modification by users is likely to produce
# unanticipated results.
#
# Copyright 2004 ARM Limited. All rights reserved.
#
# RCS $Revision$
# Checkin $Date$
# Revising $Author$

# Attributes in the library suffix.
*_4*.* $IEEE1$ARM_ISAv4
*_t*.* $IEEE1$ARM_ISAv4$THUMB_ISAv1
*_5*.* $IEEE1$ARM_ISAv5$THUMB_ISAv1
*_w*.* $IEEE1$THUMB_ISAv4$D
*_p*.* $IEEE1$THM_ISAv3M
*_2*.* $IEEE1$THUMB_ISAv4$ARM_ISAv7
*_8*.* $IEEE1$ARM_ISAv8$THUMB_ISAv5$DE$MPE$B$J$K
*_o*.* $IEEE1$A64_ISAv8
*_*e*.* $IEEE1$RWPI
*_*f*.* $IEEE1$~SHL$FPIC
*_*s*.* $IEEE1$PE
*_*v*.* $IEEE1$VFPv1
*_*m*.* $IEEE1$VFPi1$EXTD16$VFPS
*_*n*.* $IEEE1$ENUMINT
*_*u*.* $IEEE1$WCHAR32
*_r*.* $IEEE1$A64_ISAv8$SIGN_RET_ADDR
*_a*.* $IEEE1$A64_ISAv8$SIGN_RET_ADDR$TAGGED_STACK

# Sets of library prefixes which denote the same library set and
# vary the attributes.
fz_* $IEEE1$STANDARDLIB
g_* $IEEE1$STANDARDLIB$IEEEX fz
f_* $IEEE1$STANDARDLIB$IEEEF fz
fj_* $IEEE1$STANDARDLIB$IEEEJ fz
mf_* $IEEE1$MICROLIB fz

c2_* $IEEE1$STANDARDLIB
c_* $IEEE1$STANDARDLIB
mc_* $IEEE1$MICROLIB c

20 changes: 10 additions & 10 deletions src/ST7735S.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ static void Close( void )
static void Sleep( void )
{
send_cmd_byte( 0x10 );
SetDisplayStatus( DISPLAY_SLEEPING );
DMSetStatus( DISPLAY_SLEEPING );
}

static void Wakeup( void )
{
send_cmd_byte( 0x11 );

if ( display_status == DISPLAY_SLEEPING )
TMCreateTask( 120, SetDisplayStatus, DISPLAY_ON, 0, 0, 0 );
TMCreateTask( 120, (void(*)(uint32_t))DMSetStatus, DISPLAY_ON, 0, 0, 0 );
}

static void Reset( void )
Expand Down Expand Up @@ -338,7 +338,7 @@ static int draw_char( const uint16_t c, int x, int y )
return cw;
}

static void Print( const char *str, const rect_t *r )
static void Print( const char *str, const rect_t *r, unsigned align )
{
if ( !font ) return;

Expand All @@ -363,12 +363,12 @@ void rainbow( void )

for ( int l = 0 ; l < 160 ; ++l )
{
g = HDIV_Div( 64 * l, 160 );
g = 64 * l / 160;

for ( int c = 0 ; c < 80 ; ++c )
{
r = HDIV_Div( 32 * c, 80 );
b = HDIV_Div( 32 * ( c + l ), 240 ) ^ 0x1F;
r = 32 * c / 80;
b = ( 32 * ( c + l ) / 240 ) ^ 0x1F;

uint32_t c = b << 11 | g << 5 | r;
send_data_word( c );
Expand All @@ -385,7 +385,7 @@ void rainbow( void )

static uint8_t startup_task_id;

void startup_task( uint32_t step )
static void startup_task( uint32_t step )
{
switch ( step )
{
Expand All @@ -407,19 +407,19 @@ void startup_task( uint32_t step )
case 3:
Init();
TMDestroyTask( startup_task_id );
SetDisplayStatus( DISPLAY_ON );
DMSetStatus( DISPLAY_ON );
break;
}
}

void Startup( void )
static void Startup( void )
{
if ( startup_task_id )
{
TMDestroyTask( startup_task_id );
}

SetDisplayStatus( DISPLAY_OFF );
DMSetStatus( DISPLAY_OFF );
TMCreateTask( 0, startup_task, 0, 1, 120, &startup_task_id );
}

Expand Down
8 changes: 1 addition & 7 deletions src/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ void ConfigureADC()
}


void ConfigureHDIV()
{
CLK_EnableModuleClock( HDIV_MODULE );
}


uint32_t ADCSample( uint32_t ch, int count )
{
uint32_t sample;
Expand All @@ -231,6 +225,6 @@ uint32_t ADCSample( uint32_t ch, int count )
sample += ADC_GET_CONVERSION_DATA( ADC, ch );
}

sample = HDIV_Div( sample, count );
sample = sample / count;
return sample;
}
18 changes: 12 additions & 6 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ uint16_t bgcolor;


//------------------------------------------------------------------------------
// Inform the display manager of the display we'll use.
// Display startup.
//------------------------------------------------------------------------------
void SetDisplay( const display_t *d )
// Initializes the display global variable and calls the startup process.
//------------------------------------------------------------------------------
void DMStartup()
{
display = d;
display = &ST7735S;
display->Startup();
}


void SetDisplayStatus( uint32_t status )
//------------------------------------------------------------------------------
// Display status change
//------------------------------------------------------------------------------
void DMSetStatus( DISPLAY_STATUS status )
{
display_status = status;
EMSendEvent1P( EVENT_DISPLAY, EV_D_DISPLAY_STATUS, status );
}


DISPLAY_STATUS GetDisplayStatus( void )
DISPLAY_STATUS DMGetStatus( void )
{
return display_status;
}
Expand Down Expand Up @@ -60,7 +66,7 @@ void FormatNumber( char *str, uint32_t num, int nbdig, int nbdec, int exp )

while ( num )
{
num = HDIV_Div( num, 10 );
num /= 10;
uint16_t rem = HDIV->DIVREM;
buf[idx++] = '0' + rem;
}
Expand Down
79 changes: 79 additions & 0 deletions src/div.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
; /*****************************************************************************
; *
; * Replacement for aeabi standard division functions
; * Using the NUC126 hardware divider
; *
; *****************************************************************************/

AREA |.text|, CODE, READONLY

HDIV EQU 0x50014000


; Signed division using the hardware divider.
; ~20 cycles

ALIGN
__aeabi_idivmod PROC
ROUT
EXPORT __aeabi_idivmod

LDR R2, = HDIV
STR R0, [ R2, #0 ]
STR R1, [ R2, #4 ]
LDR R0, [ R2, #8 ]
LDR R1, [ R2, #12 ]
BX LR

ENDP

ALIGN
__aeabi_idiv PROC
ROUT
EXPORT __aeabi_idiv

LDR R2, = HDIV
STR R0, [ R2, #0 ]
STR R1, [ R2, #4 ]
LDR R0, [ R2, #8 ]
BX LR

ENDP


; Unsigned divisions are just signed divisions,
; assuming that divisor and dividend never exceed 2^31-1.
; That's lazy but good enough.

__aeabi_uidivmod EQU __aeabi_idivmod
EXPORT __aeabi_uidivmod

__aeabi_uidiv EQU __aeabi_idiv
EXPORT __aeabi_uidiv


; Just in case

IF {FALSE}
ALIGN
__aeabi_uidivmod PROC
ROUT
EXPORT __aeabi_uidivmod

B __aeabi_idivmod

ENDP

ALIGN
__aeabi_uidiv PROC
ROUT
EXPORT __aeabi_uidiv

B __aeabi_idiv

ENDP
ENDIF

ALIGN

END
4 changes: 2 additions & 2 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ static uint8_t embuffer[ 20 * sizeof( Event_t ) ];
// For debugging pruposes
static void PrintEvent( const Event_t *ev )
{
if ( GetDisplayStatus() != DISPLAY_ON ) return;
if ( DMGetStatus() != DISPLAY_ON ) return;
rect_t r = { 11, 150, 79, 159 };
char buf[12];
snprintf( buf, sizeof( buf ), "%02X %02X %02X %02X", ev->type, ev->k, ev->p1, ev->p2 );
display->Print( buf, &r );
display->Print( buf, &r, 0 );
}


Expand Down
2 changes: 2 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void SystemInit( void )
SYS_UnlockReg();
SYS_DISABLE_POR();

CLK_EnableModuleClock( HDIV_MODULE );

CLK_EnableXtalRC( CLK_PWRCTL_HIRCEN_Msk );
CLK_WaitClockReady( CLK_STATUS_HIRCSTB_Msk );
CLK_SetHCLK( CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1) );
Expand Down
5 changes: 1 addition & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void StartupDevices( void )
ConfigureADC();
ConfigurePWM1();
ConfigureSPI0();
ConfigureHDIV();
}


Expand Down Expand Up @@ -71,9 +70,7 @@ int main( void )
EMStartup();
BMStartup();
SMStartup();

SetDisplay( &ST7735S );
display->Startup();
DMStartup();

while ( 1 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void SMShowScreen( SCREENID sid )
//------------------------------------------------------------------------------
void SMRefresh( void )
{
if ( GetDisplayStatus() != DISPLAY_ON ) return;
if ( DMGetStatus() != DISPLAY_ON ) return;

uint32_t t = GetSysTick();

Expand Down
6 changes: 3 additions & 3 deletions src/screens/screen_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ extern int ScrMainRefresh( void )
BMGetCells( &vbat1, &vbat2 );

FormatNumber( buf, vbat1, 4, 3, 3 );
display->Print( buf, &r );
display->Print( buf, &r, 0 );

FormatNumber( buf, vbat2, 4, 3, 3 );
r.left = 33;
display->Print( buf, &r );
display->Print( buf, &r, 0 );

BATT_STATUS bs = BMGetStatus();
if ( bs != BATT_UNK )
{
r.left = 66;
display->Print( bs == BATT_OK ? "OK" : "LO" , &r );
display->Print( bs == BATT_OK ? "OK" : "LO" , &r, 0 );
}
}

Expand Down

0 comments on commit bee5e7f

Please sign in to comment.