[skip ci] Merge pull request #16 from Tunas1337/t9-texting

Add t9 texting
pull/17/head
Piotr Lewandowski (SQ9P) 2023-07-09 16:06:04 +02:00 zatwierdzone przez GitHub
commit bedd38fc5d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
10 zmienionych plików z 512 dodań i 1 usunięć

Wyświetl plik

@ -3,4 +3,5 @@ add_subdirectory(rssi_printer)
add_subdirectory(rssi_sbar)
add_subdirectory(most_useless_mod)
add_subdirectory(pong)
add_subdirectory(spectrum)
add_subdirectory(spectrum)
add_subdirectory(t9_texting)

Wyświetl plik

@ -0,0 +1,79 @@
set(NAME t9_texting)
set(MCU_TARGET_FILES_DIR ../mcu_target_common)
add_executable(${NAME}
main.cpp
hardware/hardware.cpp
dp32g030.s
)
target_link_libraries(${NAME}
orginal_fw
uv_k5_system
lcd
)
target_include_directories(${NAME} PUBLIC
./
Drivers/CMSIS/Device/ST/STM32G0xx/Include
Drivers/CMSIS/DSP/Include
Drivers/CMSIS/Include
)
target_compile_definitions(${NAME} PRIVATE
${STM32_DEFINES}
$<$<CONFIG:Debug>:DEBUG_ENABLED>
)
target_compile_options(${NAME} PRIVATE
${COMPILER_OPTIONS}
-flto
)
target_link_options(${NAME} PRIVATE
#-print-multi-lib
-T ${CMAKE_CURRENT_SOURCE_DIR}/memory.ld
-flto
-mcpu=cortex-m0
-mthumb
-mfpu=auto
-mfloat-abi=soft
-specs=nosys.specs
-specs=nano.specs
-lc
-lm
-lnosys
-Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections
-Wl,--print-memory-usage
-Wstack-usage=128
-Wno-register
)
add_custom_command(TARGET ${NAME}
POST_BUILD
COMMAND arm-none-eabi-size ${NAME}
)
#convert to hex
add_custom_command(TARGET ${NAME}
POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${NAME} ${NAME}.hex
COMMAND arm-none-eabi-objcopy -O binary ${NAME} ${NAME}.bin
)
get_target_property(BOOTLOADER_BIN_PATH orginal_fw BOOTLOADER_BIN_PATH)
add_custom_command(TARGET ${NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "generating full binary with bootloader to ${NAME}_with_bootloader.bin"
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/fw_merger.py ${BOOTLOADER_BIN_PATH} ${NAME}.bin ${NAME}_with_bootloader.bin
)
add_custom_target(${NAME}_flash
COMMAND openocd -f interface/cmsis-dap.cfg -f ${PROJECT_SOURCE_DIR}/openocd_scripts/dp32g030.cfg -c "write_image ${PROJECT_SOURCE_DIR}/build/src/rssi_printer/rssi_printer.bin 0x1000" -c "halt" -c "shutdown"
DEPENDS ${NAME}
)
add_custom_target(${NAME}_encoded
COMMAND python ${PROJECT_SOURCE_DIR}/tools/fw_tools/python-utils/fw_pack.py ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.bin ${CMAKE_CURRENT_SOURCE_DIR}/../orginal_fw/k5_26_encrypted_18to1300MHz.ver.bin ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_encoded.bin
DEPENDS ${NAME}
)

Wyświetl plik

@ -0,0 +1,18 @@
.syntax unified
.cpu cortex-m0
.fpu softvfp
.thumb
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
ldr r0, =_estack
mov sp, r0 /* set stack pointer */
bl main
LoopForever:
b LoopForever
.size Reset_Handler, .-Reset_Handler

Wyświetl plik

@ -0,0 +1,17 @@
#include "registers.hpp"
class CExec final
{
public:
CExec(){};
void InterruptCallback()
{
CheckButtons();
}
private:
void CheckButtons() const
{
}
};

Wyświetl plik

@ -0,0 +1,16 @@
import sys
def merge_files(in1, in2, out):
f1 = open(in1, 'rb')
f2 = open(in2, 'rb')
fo = open(out, 'wb')
fo.write(f1.read())
fo.write(f2.read())
fo.close()
f1.close()
f2.close()
if __name__ == '__main__':
args = sys.argv
merge_files(args[1], args[2], args[3])

Wyświetl plik

@ -0,0 +1,50 @@
#include "hardware.hpp"
#include "registers.hpp"
using namespace Hardware;
void TPower::EnableDbg()
{
GPIOB->DIR &= ~(GPIO_PIN_11|GPIO_PIN_14);
// PB11 alternate fx to SWDIO
GPIO->PORTB_SEL1 &= ~(0b1111 << 12);
GPIO->PORTB_SEL1 |= (0b1 << 12);
// PB14 alternate fx to SWDIO
GPIO->PORTB_SEL1 &= ~(0b1111 << 24);
GPIO->PORTB_SEL1 |= (0b1 << 24);
}
void TSystem::Delay(unsigned int u32Ticks)
{
for(volatile unsigned int i = 0; i < u32Ticks; i++)
{
__asm volatile ("dsb sy" : : : "memory");
}
}
void TFlashLight::On()
{
GPIOC->DATA |= 1 << 3;
}
void TFlashLight::Off()
{
GPIOC->DATA &= ~(1 << 3);
}
void TFlashLight::Toggle()
{
GPIOC->DATA ^= 1 << 3;
}
void TFlashLight::BlinkSync(unsigned char u8BlinksCnt)
{
for(unsigned char i = 0; i < u8BlinksCnt*2; i++)
{
Toggle();
System.Delay(200000);
}
Off();
}

Wyświetl plik

@ -0,0 +1,29 @@
namespace Hardware
{
struct TPower
{
void EnableDbg();
};
struct TSystem
{
static void Delay(unsigned int u32Ticks);
};
struct TFlashLight
{
TFlashLight(TSystem& Sys) :System(Sys){};
void On();
void Off();
void Toggle();
void BlinkSync(unsigned char u8BlinksCnt);
TSystem& System;
};
struct THardware
{
TPower Power;
TSystem System;
TFlashLight FlashLight = {System};
};
}

Wyświetl plik

@ -0,0 +1,42 @@
#include "system.hpp"
#include "hardware/hardware.hpp"
#include "registers.hpp"
#include "uv_k5_display.hpp"
#include "t9_texting.hpp"
#include <string.h>
Hardware::THardware Hw;
const System::TOrgFunctions& Fw = System::OrgFunc_01_26;
const System::TOrgData& FwData = System::OrgData_01_26;
CT9Texting<System::OrgFunc_01_26, System::OrgData_01_26> T9Texting;
int main()
{
System::JumpToOrginalFw();
return 0;
}
void MultiIrq_Handler(unsigned int u32IrqSource)
{
unsigned int u32Dummy;
System::TCortexM0Stacking* pStackedRegs =
(System::TCortexM0Stacking*)(((unsigned int*)&u32Dummy) + 1);
static bool bFirstInit = false;
if(!bFirstInit)
{
System::CopyDataSection();
__libc_init_array();
bFirstInit = true;
}
bool bPreventWhileKeypadPolling = pStackedRegs->LR > (unsigned int)Fw.PollKeyboard &&
pStackedRegs->PC < (unsigned int)Fw.PollKeyboard + 0x100; // i made a mistake and compared PC and LR, but this works fine xD
static unsigned int u32StupidCounter = 1;
if(u32StupidCounter++ > 200 && !bPreventWhileKeypadPolling)
{
T9Texting.Handle();
}
}

Wyświetl plik

@ -0,0 +1,88 @@
ENTRY(Reset_Handler)
MEMORY
{
RAM (rwx) : ORIGIN = 0x2000138C, LENGTH = 256
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 60K
}
_estack = 0x20001388;
SECTIONS
{
. = 0x0;
.isr_vectors :
{
. = ALIGN(4);
KEEP(*(.isr_vectors))
. = ALIGN(4);
} >FLASH
.org_fw_rest :
{
. = ALIGN(4);
KEEP(*(.org_fw_rest))
} > FLASH
.org_vectors :
{
. = ALIGN(4);
__org_vectors_start = .;
KEEP(*(.org_vectors))
} > FLASH
.text :
{
. = ALIGN(4);
*(.text)
*(.text*)
*(.rodata)
*(.rodata*)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
} >FLASH
.preinit_array :
{
__preinit_array_start = .;
KEEP (*(.preinit_array*))
__preinit_array_end = .;
} >FLASH
.init_array :
{
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
__init_array_end = .;
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
_flash_data_start = .;
} >FLASH
_sidata = LOADADDR(.data);
.data : AT (_flash_data_start)
{
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
*(.ramsection)
_edata = .;
} >RAM
.bss :
{
. = ALIGN(4);
_sbss = .;
*(.bss)
_ebss = .;
} >RAM
}

Wyświetl plik

@ -0,0 +1,171 @@
#pragma once
#include "system.hpp"
#include "uv_k5_display.hpp"
template <const System::TOrgFunctions &Fw, const System::TOrgData &FwData>
class CT9Texting
{
public:
CT9Texting()
: DisplayBuff(FwData.pDisplayBuffer),
Display(DisplayBuff),
bDisplayCleared(true),
bEnabled(0)
{
};
char T9_table[10][4] = {{' ', '\0', '\0', '\0'}, {'\0', '\0', '\0', '\0'}, {'a', 'b', 'c', '\0'}, {'d', 'e', 'f', '\0'}, {'g', 'h', 'i', '\0'}, {'j', 'k', 'l', '\0'}, {'m', 'n', 'o', '\0'}, {'p', 'q', 'r', 's'}, {'t', 'u', 'v', '\0'}, {'w', 'x', 'y', 'z'}};
unsigned char numberOfLettersAssignedToKey[10] = {1, 0, 3, 3, 3, 3, 3, 4, 3, 4};
unsigned char prev_key = 0, prev_letter = 0;
char cMessage[30];
unsigned char c_index = 0;
bool keyReleased = true;
void insert_char_to_cMessage(unsigned char key)
{
if (prev_key == key && key != 14)
{
c_index = (c_index > 0) ? c_index - 1 : 0;
cMessage[c_index++] = T9_table[key][(++prev_letter) % numberOfLettersAssignedToKey[key]];
}
else
{
prev_letter = 0;
cMessage[c_index++] = T9_table[key][prev_letter];
}
cMessage[c_index] = '\0';
prev_key = key;
}
void process_starkey()
{
prev_key = 14;
prev_letter = 0;
}
void process_backspace()
{
c_index = (c_index > 0) ? c_index - 1 : 0;
cMessage[c_index] = ' ';
}
void Handle()
{
if (!(GPIOC->DATA & 0b1))
{
return;
}
if (!FreeToDraw())
{
if (!bDisplayCleared)
{
bDisplayCleared = true;
ClearDrawings();
// Clear cMessage
memset(cMessage, 0, 30);
c_index = 0;
Fw.FlushFramebufferToScreen();
}
return;
}
if (bDisplayCleared)
{
}
bDisplayCleared = false;
unsigned char key;
key = u8LastBtnPressed;
if (key == 0xff)
{
keyReleased = true;
return;
}
else if (keyReleased)
{
keyReleased = false;
if (key == 0)
{ // key 0 for space
prev_key = 0;
prev_letter = 0;
cMessage[c_index++] = ' ';
}
else if (key == 13)
{
process_backspace();
return;
}
else if (key == 14)
{
process_starkey();
return;
}
else if (key == 10)
{
bEnabled = false;
return;
}
else
{
insert_char_to_cMessage(key);
}
}
prev_key = key;
// Display.DrawRectangle(0,0, 7, 7, 0);
ClearDrawings();
Fw.PrintTextOnScreen(cMessage, 0, 128, 0, 8, 0);
Fw.FlushFramebufferToScreen();
}
private:
bool
FreeToDraw()
{
bool bFlashlight = (GPIOC->DATA & GPIO_PIN_3);
if (bFlashlight)
{
bEnabled = true;
GPIOC->DATA &= ~GPIO_PIN_3;
*FwData.p8FlashLightStatus = 3;
}
if (bEnabled)
{
u8LastBtnPressed = Fw.PollKeyboard();
}
// u8LastBtnPressed = Fw.PollKeyboard();
// if (u8LastBtnPressed == EnableKey)
// {
// u8PressCnt++;
// }
// if (u8PressCnt > (bEnabled ? 3 : PressDuration))
// {
// u8PressCnt = 0;
// bEnabled = !bEnabled;
// }
return bEnabled;
}
void ClearDrawings()
{
memset(FwData.pDisplayBuffer, 0, (DisplayBuff.SizeX / 8) * DisplayBuff.SizeY);
}
TUV_K5Display DisplayBuff;
CDisplay<const TUV_K5Display> Display;
bool bDisplayCleared;
unsigned char u8LastBtnPressed;
bool bEnabled;
};