Skip to content

Commit

Permalink
Tweak larger fonts menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Dawson committed Sep 3, 2024
2 parents 24c3d48 + 39111fc commit eac0afe
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
test_dsp
*~
5 changes: 2 additions & 3 deletions rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,9 @@ void rx::run()

//process adc data as each block completes
dma_channel_wait_for_finish_blocking(adc_dma_ping);
clock_t start_time;
start_time = time_us_64();
uint32_t start_time = time_us_32();
num_ping_samples = rx_dsp_inst.process_block(ping_samples, ping_audio);
busy_time = time_us_64()-start_time;
busy_time = time_us_32()-start_time;
dma_channel_wait_for_finish_blocking(adc_dma_pong);
num_pong_samples = rx_dsp_inst.process_block(pong_samples, pong_audio);
}
Expand Down
4 changes: 2 additions & 2 deletions rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct rx_settings
struct rx_status
{
int32_t signal_strength_dBm;
clock_t busy_time;
uint32_t busy_time;
uint16_t temp;
uint16_t battery;
};
Expand Down Expand Up @@ -87,7 +87,7 @@ class rx
uint32_t pwm_max;

//store busy time for performance monitoring
clock_t busy_time;
uint32_t busy_time;

public:
rx(rx_settings & settings_to_apply, rx_status & status);
Expand Down
56 changes: 32 additions & 24 deletions ssd1306.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ inline void ssd1306_flip(ssd1306_t *p, uint8_t flip) {
}
}

inline void ssd1306_clear(ssd1306_t *p, bool colour) {
memset(p->buffer, 0xff*colour, p->bufsize);
}

inline void ssd1306_type(ssd1306_t *p, uint8_t type) {
if (type) {
p->disp_col_offset = 2;
Expand All @@ -158,17 +162,19 @@ inline void ssd1306_type(ssd1306_t *p, uint8_t type) {
}
}

inline void ssd1306_clear(ssd1306_t *p) {
memset(p->buffer, 0, p->bufsize);
}

void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y) {
void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y, bool colour) {
if(x>=p->width || y>=p->height) return;

// each page is 129 bytes long for the oled cmd byte at the start
p->buffer[1 + x + (1 + p->width)*(y>>3) ] |= 0x1<<(y&0x07); // y>>3==y/8 && y&0x7==y%8
if (colour) {
p->buffer[1 + x + (1 + p->width)*(y>>3) ] |= 0x1<<(y&0x07); // y>>3==y/8 && y&0x7==y%8
} else {
p->buffer[1 + x + (1 + p->width)*(y>>3) ] &= ~(0x1<<(y&0x07)); // y>>3==y/8 && y&0x7==y%8
}
}

void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2, bool colour) {
if(x1>x2) {
swap(&x1, &x2);
swap(&y1, &y2);
Expand All @@ -178,36 +184,38 @@ void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t
if(y1>y2)
swap(&y1, &y2);
for(int32_t i=y1; i<=y2; ++i)
ssd1306_draw_pixel(p, x1, i);
ssd1306_draw_pixel(p, x1, i, colour);
return;
}

float m=(float) (y2-y1) / (float) (x2-x1);

for(int32_t i=x1; i<=x2; ++i) {
float y=m*(float) (i-x1)+(float) y1;
ssd1306_draw_pixel(p, i, (uint32_t) y);
ssd1306_draw_pixel(p, i, (uint32_t) y, colour);
}
}

void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool colour) {
for(uint32_t i=0; i<width; ++i)
for(uint32_t j=0; j<height; ++j)
ssd1306_draw_pixel(p, x+i, y+j);
ssd1306_draw_pixel(p, x+i, y+j, colour);

}

void ssd13606_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
ssd1306_draw_line(p, x, y, x+width, y);
ssd1306_draw_line(p, x, y+height, x+width, y+height);
ssd1306_draw_line(p, x, y, x, y+height);
ssd1306_draw_line(p, x+width, y, x+width, y+height);
void ssd13606_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool colour) {
ssd1306_draw_line(p, x, y, x+width, y, colour);
ssd1306_draw_line(p, x, y+height, x+width, y+height, colour);
ssd1306_draw_line(p, x, y, x, y+height, colour);
ssd1306_draw_line(p, x+width, y, x+width, y+height, colour);
}

void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c) {
void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c, bool colour) {
if(c<font[3]||c>font[4])
return;

ssd1306_draw_square( p, x, y, (font[1]+font[2])*scale, font[0]*scale, !colour);

uint32_t parts_per_line=(font[0]>>3)+((font[0]&7)>0);
for(uint8_t w=0; w<font[1]; ++w) { // width
uint32_t pp=(c-font[3])*font[1]*parts_per_line+w*parts_per_line+5;
Expand All @@ -216,26 +224,26 @@ void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t

for(int8_t j=0; j<8; ++j, line>>=1) {
if(line & 1)
ssd1306_draw_square(p, x+w*scale, y+((lp<<3)+j)*scale, scale, scale);
ssd1306_draw_square(p, x+w*scale, y+((lp<<3)+j)*scale, scale, scale, colour);
}

++pp;
}
}
}

void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s) {
void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s, bool colour) {
for(int32_t x_n=x; *s; x_n+=(font[1]+font[2])*scale) {
ssd1306_draw_char_with_font(p, x_n, y, scale, font, *(s++));
ssd1306_draw_char_with_font(p, x_n, y, scale, font, *(s++), colour);
}
}

void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c) {
ssd1306_draw_char_with_font(p, x, y, scale, font_8x5, c);
void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c, bool colour) {
ssd1306_draw_char_with_font(p, x, y, scale, font_8x5, c, colour);
}

void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s) {
ssd1306_draw_string_with_font(p, x, y, scale, font_8x5, s);
void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s, bool colour) {
ssd1306_draw_string_with_font(p, x, y, scale, font_8x5, s, colour);
}

static inline uint32_t ssd1306_bmp_get_val(const uint8_t *data, const size_t offset, uint8_t size) {
Expand Down Expand Up @@ -290,7 +298,7 @@ void ssd1306_bmp_show_image_with_offset(ssd1306_t *p, const uint8_t *data, const
for(uint32_t y=biHeight>0?biHeight-1:0; y!=border; y+=step) {
for(uint32_t x=0; x<biWidth; ++x) {
if(((img_data[x>>3]>>(7-(x&7)))&1)==color_val)
ssd1306_draw_pixel(p, x_offset+x, y_offset+y);
ssd1306_draw_pixel(p, x_offset+x, y_offset+y, 1);
}
img_data+=bytes_per_line;
}
Expand Down
27 changes: 18 additions & 9 deletions ssd1306.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,17 @@ void ssd1306_show(ssd1306_t *p);
@param[in] p : instance of display
*/
void ssd1306_clear(ssd1306_t *p);
void ssd1306_clear(ssd1306_t *p, bool colour);

/**
@brief draw pixel on buffer
@param[in] p : instance of display
@param[in] x : x position
@param[in] y : y position
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y);
void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y, bool colour);

/**
@brief draw pixel on buffer
Expand All @@ -183,8 +184,9 @@ void ssd1306_draw_pixel(ssd1306_t *p, uint32_t x, uint32_t y);
@param[in] y1 : y position of starting point
@param[in] x2 : x position of end point
@param[in] y2 : y position of end point
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t y2, bool colour);

/**
@brief draw filled square at given position with given size
Expand All @@ -194,8 +196,9 @@ void ssd1306_draw_line(ssd1306_t *p, int32_t x1, int32_t y1, int32_t x2, int32_t
@param[in] y : y position of starting point
@param[in] width : width of square
@param[in] height : height of square
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool colour);

/**
@brief draw empty square at given position with given size
Expand All @@ -205,8 +208,9 @@ void ssd1306_draw_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, u
@param[in] y : y position of starting point
@param[in] width : width of square
@param[in] height : height of square
@param[in] colour : 1=white, 0=black
*/
void ssd13606_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
void ssd13606_draw_empty_square(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool colour);

/**
@brief draw monochrome bitmap with offset
Expand Down Expand Up @@ -237,8 +241,9 @@ void ssd1306_bmp_show_image(ssd1306_t *p, const uint8_t *data, const long size);
@param[in] scale : scale font to n times of original size (default should be 1)
@param[in] font : pointer to font
@param[in] c : character to draw
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c);
void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, char c, bool colour);

/**
@brief draw char with builtin font
Expand All @@ -248,8 +253,9 @@ void ssd1306_draw_char_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t
@param[in] y : y starting position of char
@param[in] scale : scale font to n times of original size (default should be 1)
@param[in] c : character to draw
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c);
void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, char c, bool colour);

/**
@brief draw string with given font
Expand All @@ -260,8 +266,10 @@ void ssd1306_draw_char(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, cha
@param[in] scale : scale font to n times of original size (default should be 1)
@param[in] font : pointer to font
@param[in] s : text to draw
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s );
void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const uint8_t *font, const char *s, bool colour);

/**
@brief draw string with builtin font
Expand All @@ -271,8 +279,9 @@ void ssd1306_draw_string_with_font(ssd1306_t *p, uint32_t x, uint32_t y, uint32_
@param[in] y : y starting position of text
@param[in] scale : scale font to n times of original size (default should be 1)
@param[in] s : text to draw
@param[in] colour : 1=white, 0=black
*/
void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s);
void ssd1306_draw_string(ssd1306_t *p, uint32_t x, uint32_t y, uint32_t scale, const char *s, bool colour);


#ifdef __cplusplus
Expand Down
Loading

0 comments on commit eac0afe

Please sign in to comment.