1.1 --- a/examples/demo/main.c Thu Nov 08 23:07:09 2018 +0100
1.2 +++ b/examples/demo/main.c Thu Nov 08 23:40:26 2018 +0100
1.3 @@ -18,9 +18,10 @@
1.4 */
1.5
1.6
1.7 -#include "pic32_c.h"
1.8 +#include "debug.h"
1.9 #include "init.h"
1.10 -#include "debug.h"
1.11 +#include "pic32_c.h"
1.12 +#include "utils.h"
1.13
1.14 /* Specific functionality. */
1.15
1.16 @@ -47,30 +48,6 @@
1.17
1.18
1.19
1.20 -/* Blink an attached LED with delays implemented using a loop. */
1.21 -
1.22 -static void blink(uint32_t delay, uint32_t port, uint32_t pins)
1.23 -{
1.24 - uint32_t counter;
1.25 -
1.26 - /* Clear outputs (LED). */
1.27 -
1.28 - CLR_REG(port, pins);
1.29 -
1.30 - while (1)
1.31 - {
1.32 - counter = delay;
1.33 -
1.34 - while (counter--) __asm__(""); /* retain loop */
1.35 -
1.36 - /* Invert outputs (LED). */
1.37 -
1.38 - INV_REG(port, pins);
1.39 - }
1.40 -}
1.41 -
1.42 -
1.43 -
1.44 /* Main program. */
1.45
1.46 void main(void)
2.1 --- a/examples/vga/main.c Thu Nov 08 23:07:09 2018 +0100
2.2 +++ b/examples/vga/main.c Thu Nov 08 23:40:26 2018 +0100
2.3 @@ -18,19 +18,19 @@
2.4 */
2.5
2.6
2.7 -#include "pic32_c.h"
2.8 +#include "debug.h"
2.9 +#include "display.h"
2.10 +#include "font.h"
2.11 #include "init.h"
2.12 -#include "debug.h"
2.13 +#include "pic32_c.h"
2.14 +#include "utils.h"
2.15 +#include "vga_display.h"
2.16
2.17 /* Specific functionality. */
2.18
2.19 #include "devconfig.h"
2.20 -#include "display.h"
2.21 #include "display_config.h"
2.22 -#include "font.h"
2.23 #include "main.h"
2.24 -#include "vga.h"
2.25 -#include "vga_display.h"
2.26
2.27
2.28
2.29 @@ -106,34 +106,6 @@
2.30
2.31
2.32
2.33 -/* Busy wait. */
2.34 -
2.35 -static void wait(uint32_t delay)
2.36 -{
2.37 - uint32_t counter = delay;
2.38 -
2.39 - if (!delay) return;
2.40 - while (counter--) __asm__(""); /* retain loop */
2.41 -}
2.42 -
2.43 -/* Blink an attached LED with delays implemented using a loop. */
2.44 -
2.45 -static void blink(uint32_t delay, uint32_t port, uint32_t pins)
2.46 -{
2.47 - /* Clear outputs (LED). */
2.48 -
2.49 - CLR_REG(port, pins);
2.50 -
2.51 - while (1)
2.52 - {
2.53 - wait(delay);
2.54 -
2.55 - /* Invert outputs (LED). */
2.56 -
2.57 - INV_REG(port, pins);
2.58 - }
2.59 -}
2.60 -
2.61 /* Copy to the store from the display, then blit the image. */
2.62
2.63 static void plot_sprite(uint8_t *background, int x, int y)
2.64 @@ -155,18 +127,6 @@
2.65 x, y, -1, 1);
2.66 }
2.67
2.68 -/* Wrap a value within the bounds [0, limit). */
2.69 -
2.70 -static int wrap_value(int value, int limit)
2.71 -{
2.72 - if (value < 0)
2.73 - return limit - (-value % limit);
2.74 - else if (value >= limit)
2.75 - return (value - limit) % limit;
2.76 - else
2.77 - return value;
2.78 -}
2.79 -
2.80 /* Plot the revealed region at the edge of the screen after scrolling. */
2.81
2.82 static void plot_screen_edge(int xorigin, int yorigin, int xstep)
3.1 --- a/include/debug.h Thu Nov 08 23:07:09 2018 +0100
3.2 +++ b/include/debug.h Thu Nov 08 23:40:26 2018 +0100
3.3 @@ -20,6 +20,8 @@
3.4 #ifndef __DEBUG_H__
3.5 #define __DEBUG_H__
3.6
3.7 +#include <stdint.h>
3.8 +
3.9 /* Register output functions using UART1. */
3.10
3.11 void rbits(uint32_t reg);
3.12 @@ -43,4 +45,8 @@
3.13 void uart_write_nl(void);
3.14 void uart_write_string(const char *s);
3.15
3.16 +/* Output signal functions. */
3.17 +
3.18 +void blink(uint32_t delay, uint32_t port, uint32_t pins);
3.19 +
3.20 #endif /* __DEBUG_H__ */
4.1 --- a/lib/debug.c Thu Nov 08 23:07:09 2018 +0100
4.2 +++ b/lib/debug.c Thu Nov 08 23:40:26 2018 +0100
4.3 @@ -19,6 +19,9 @@
4.4
4.5 #include "pic32_c.h"
4.6 #include "debug.h"
4.7 +#include "utils.h"
4.8 +
4.9 +
4.10
4.11 /* Register output functions using UART1. */
4.12
4.13 @@ -106,3 +109,23 @@
4.14 while (*s)
4.15 uart_write(*s++);
4.16 }
4.17 +
4.18 +
4.19 +
4.20 +/* Blink an attached LED with delays implemented using a loop. */
4.21 +
4.22 +void blink(uint32_t delay, uint32_t port, uint32_t pins)
4.23 +{
4.24 + /* Clear outputs (LED). */
4.25 +
4.26 + CLR_REG(port, pins);
4.27 +
4.28 + while (1)
4.29 + {
4.30 + wait(delay);
4.31 +
4.32 + /* Invert outputs (LED). */
4.33 +
4.34 + INV_REG(port, pins);
4.35 + }
4.36 +}
5.1 --- a/mk/common.mk Thu Nov 08 23:07:09 2018 +0100
5.2 +++ b/mk/common.mk Thu Nov 08 23:40:26 2018 +0100
5.3 @@ -49,8 +49,8 @@
5.4 # Application-specific files appear after the above but before those below in
5.5 # the application Makefiles.
5.6
5.7 -COMMON_SRC = $(LIBDIR)/payload.c $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/cpu.S
5.8 -COMMON_OBJ = $(LIBDIR)/payload.o $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/cpu.o
5.9 +COMMON_SRC = $(LIBDIR)/payload.c $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/utils.c $(LIBDIR)/cpu.S
5.10 +COMMON_OBJ = $(LIBDIR)/payload.o $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/utils.o $(LIBDIR)/cpu.o
5.11
5.12 DISPLAY_COMMON_SRC = $(LIBDIR)/display.c $(LIBDIR)/font.c
5.13 DISPLAY_COMMON_OBJ = $(LIBDIR)/display.o $(LIBDIR)/font.o