Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve architecture and reduce code #34

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ version:
SUFFIX_OBJ := rel

FILES_PRJ := $(PATH_SRC)/app/app_hello.c \
$(PATH_SRC)/app/app_lcd_util.c \
$(PATH_SRC)/app/app_led.c \
$(PATH_SRC)/app/app_led_util.c \
$(PATH_SRC)/mcal/mcal_gpt.c \
$(PATH_SRC)/os/os.c \
$(PATH_SRC)/startup/crt0.s
Expand Down
4 changes: 2 additions & 2 deletions build/ti84-ref_app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<ItemGroup>
<ClCompile Include="..\src\app\app_hello.c" />
<ClCompile Include="..\src\app\app_led.c" />
<ClCompile Include="..\src\app\app_led_util.c" />
<ClCompile Include="..\src\app\app_lcd_util.c" />
<ClCompile Include="..\src\app\app_main.c" />
<ClCompile Include="..\src\mcal\mcal_gpt.c" />
<ClCompile Include="..\src\os\os.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\app\app_led_util.h" />
<ClInclude Include="..\src\app\app_lcd_util.h" />
<ClInclude Include="..\src\mcal\mcal_gpt.h" />
<ClInclude Include="..\src\os\os.h" />
<ClInclude Include="..\src\startup\asm_util.h" />
Expand Down
4 changes: 2 additions & 2 deletions build/ti84-ref_app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<ClCompile Include="..\src\app\app_led.c">
<Filter>src\app</Filter>
</ClCompile>
<ClCompile Include="..\src\app\app_led_util.c">
<ClCompile Include="..\src\app\app_lcd_util.c">
<Filter>src\app</Filter>
</ClCompile>
<ClCompile Include="..\src\mcal\mcal_gpt.c">
Expand All @@ -64,7 +64,7 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\app\app_led_util.h">
<ClInclude Include="..\src\app\app_lcd_util.h">
<Filter>src\app</Filter>
</ClInclude>
<ClInclude Include="..\src\startup\asm_util.h">
Expand Down
26 changes: 7 additions & 19 deletions src/app/app_hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <stdbool.h>

#include <app/app_led_util.h>
#include <app/app_lcd_util.h>

static void app_hello_hello(void);
static void app_hello_world(void);
Expand All @@ -29,31 +29,19 @@ void app_hello_task(void)

static void app_hello_hello(void)
{
app_led_util_home2();
app_led_util_putc('h');
app_led_util_putc('e');
app_led_util_putc('l');
app_led_util_putc('l');
app_led_util_putc('o');
app_lcd_util_home2();
app_lcd_util_puts("hello");
}

static void app_hello_world(void)
{
app_led_util_home2();
app_led_util_putc('w');
app_led_util_putc('o');
app_led_util_putc('r');
app_led_util_putc('l');
app_led_util_putc('d');
app_lcd_util_home2();
app_lcd_util_puts("world");
}

static void app_hello_clear(void)
{
app_led_util_home2();
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
app_lcd_util_home2();
app_lcd_util_puts(" ");
}

32 changes: 24 additions & 8 deletions src/app/app_led_util.c → src/app/app_lcd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
// Distributed under The Unlicense
//

#include <app/app_led_util.h>
#include <app/app_lcd_util.h>

void app_led_util_putc(char c) ATTRIBUTE_NAKED
#define NULL_PTR (void*) 0

static void app_lcd_util_putc(char c) ATTRIBUTE_NAKED;

void app_lcd_util_puts(const char* p_str)
{
(void) c;
char c;

__asm__("rst 0x28\n" ".dw #0x4504\n");
__asm__("ret\n");
while((p_str != NULL_PTR) && ((c = *p_str) != '\0'))
{
app_lcd_util_putc(c);

++p_str;
}
}

void app_led_util_home1(void) ATTRIBUTE_NAKED
void app_lcd_util_home1(void) ATTRIBUTE_NAKED
{
__asm__("ld b,#0x02\n");
__asm__("ld a,b\n");
Expand All @@ -24,7 +32,7 @@ void app_led_util_home1(void) ATTRIBUTE_NAKED
__asm__("ret\n");
}

void app_led_util_home2(void) ATTRIBUTE_NAKED
void app_lcd_util_home2(void) ATTRIBUTE_NAKED
{
__asm__("ld b,#0x03\n");
__asm__("ld a,b\n");
Expand All @@ -35,9 +43,17 @@ void app_led_util_home2(void) ATTRIBUTE_NAKED
__asm__("ret\n");
}

void app_led_util_init(void) ATTRIBUTE_NAKED
void app_lcd_util_init(void) ATTRIBUTE_NAKED
{
__asm__("rst 0x28\n" ".dw #0x4540\n");
__asm__("rst 0x28\n" ".dw #0x4558\n");
__asm__("ret\n");
}

static void app_lcd_util_putc(char c) ATTRIBUTE_NAKED
{
(void) c;

__asm__("rst 0x28\n" ".dw #0x4504\n");
__asm__("ret\n");
}
9 changes: 5 additions & 4 deletions src/app/app_led_util.h → src/app/app_lcd_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
// curCol #0x844C
// _PutC #0x4504

void app_led_util_putc (char c) ATTRIBUTE_NAKED;
void app_led_util_home1 (void) ATTRIBUTE_NAKED;
void app_led_util_home2 (void) ATTRIBUTE_NAKED;
void app_led_util_init (void) ATTRIBUTE_NAKED;
void app_lcd_util_puts(const char* p_str);

void app_lcd_util_home1(void) ATTRIBUTE_NAKED;
void app_lcd_util_home2(void) ATTRIBUTE_NAKED;
void app_lcd_util_init (void) ATTRIBUTE_NAKED;

#endif // APP_LED_UTIL_2024_01_07_H
22 changes: 8 additions & 14 deletions src/app/app_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under The Unlicense
//

#include <app/app_led_util.h>
#include <app/app_lcd_util.h>

static void app_led_on (void);
static void app_led_off(void);
Expand All @@ -13,7 +13,7 @@ static bool app_led_is_on;

void app_led_init(void)
{
app_led_util_init();
app_lcd_util_init();
}

void app_led_task(void)
Expand All @@ -27,24 +27,18 @@ void app_led_task(void)

static void app_led_on(void)
{
app_led_util_home1();
app_led_util_putc('O');
app_led_util_putc('N');
app_led_util_putc(' ');
app_lcd_util_home1();
app_lcd_util_puts("ON ");
}

static void app_led_off(void)
{
app_led_util_home1();
app_led_util_putc('O');
app_led_util_putc('F');
app_led_util_putc('F');
app_lcd_util_home1();
app_lcd_util_puts("OFF");
}

static void app_led_clr(void)
{
app_led_util_home1();
app_led_util_putc(' ');
app_led_util_putc(' ');
app_led_util_putc(' ');
app_lcd_util_home1();
app_lcd_util_puts(" ");
}