Skip to content

Commit

Permalink
minor improvements and unchecked files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel committed Nov 12, 2020
1 parent 3e24281 commit 47b1f4e
Show file tree
Hide file tree
Showing 26 changed files with 14,606 additions and 90 deletions.
35 changes: 27 additions & 8 deletions system/apps/test4_snake/Snake.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ static const ui8 levels[] = {
"# # # #####"
"# # # #####"
"# # # #####"
"# # # #####"
"# #####"
"# #####"
"# #####"
"# # # # #####"
"# # #####"
"# # #####"
"# # #####"
"#########################"};


Expand Down Expand Up @@ -296,8 +296,10 @@ class CWndSnake : public CWnd
PrepareSprite( blk, pSprite, m_nTailDir );
else
PrepareSprite( blk, pSprite, eDirRight );

BIOS::LCD::Pattern( x<<4, (y+1)<<4, (x+1)<<4, (y+2)<<4, pSprite, 16*16 );
BIOS::LCD::BufferBegin(CRect(x<<4, (y+1)<<4, (x+1)<<4, (y+2)<<4));
BIOS::LCD::BufferWrite(pSprite, 16*16);
BIOS::LCD::BufferEnd();
// BIOS::LCD::Pattern( x<<4, (y+1)<<4, (x+1)<<4, (y+2)<<4, pSprite, 16*16 );
}

ui8 GetBlock(int x, int y)
Expand All @@ -323,9 +325,9 @@ class CWndSnake : public CWnd
int x=0, y=0;
switch (nTransform)
{
case eDirRight: x=15-_y; y=_x; break;
case eDirRight: x=_y; y=_x; break;
case eDirDown: x=15-_x; y=_y; break;
case eDirLeft: x=_y; y=15-_x; break;
case eDirLeft: x=15-_y; y=15-_x; break;
case eDirUp: x=_x; y=_y; break;
}

Expand All @@ -342,6 +344,7 @@ class CWndSnake : public CWnd

virtual void OnKey(int nKey)
{
/*
if ( nKey == BIOS::KEY::Left )
{
if ( ++m_nDir > eDirUp )
Expand All @@ -353,7 +356,23 @@ class CWndSnake : public CWnd
m_nDir--;
else
m_nDir = eDirUp;
} else */
if ( nKey == BIOS::KEY::Up )
{
m_nDir = eDirUp;
} else
if ( nKey == BIOS::KEY::Down )
{
m_nDir = eDirDown;
} else
if ( nKey == BIOS::KEY::Right )
{
m_nDir = eDirRight;
} else
if ( nKey == BIOS::KEY::Left )
{
m_nDir = eDirLeft;
} else
{
CWnd::OnKey( nKey );
return;
Expand Down
6 changes: 6 additions & 0 deletions system/apps_ds213/58_gabmini/source/MainWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ bool CMainWnd::IsRunning()

if ( ready && Settings.Trig.Sync == CSettings::Trigger::_Auto )
{
// we dont need to wait for the screen to be fully reloaded - on slow sampling modes
int screenDuration = Settings.Runtime.m_nScreenDuration*3/2+20;
if ( BIOS::SYS::GetTick() - m_lLastAcquired > 500 && BIOS::SYS::GetTick() - m_lLastRequested > screenDuration)
{
// If we enter this point, we will lost buffer-full synchronization - because we immediatelly
// request new transfer after the wptr reaches end of screen. So the "FULL" flag will be never
// set
// only if we will wait for full buffer, but that would reduce redraw time
#ifdef DS203
// + invalid first + scroll offset
bool bScreenReady = BIOS::ADC::GetPointer() > (300 + Settings.Time.InvalidFirst);
// bool canProcess = true;
#else
Expand Down
20 changes: 20 additions & 0 deletions system/apps_experiments/100_lowi2c/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
set -e

mkdir -p build
cd build

arm-none-eabi-g++ -Os -Werror -fno-common -mcpu=cortex-m3 -mthumb -msoft-float -fno-exceptions -fno-rtti -fno-threadsafe-statics -Wno-psabi -DLA104 -DARDUINO=1000 -MD -D _ARM -D STM32F10X_HD -D STM32F10X_HD -c \
../source/main.cpp \
../source/stm32/stm32f10x_i2c.c -I../../../os_library/include/ -I../source/stm32
arm-none-eabi-gcc -fPIC -mcpu=cortex-m3 -mthumb -o output.elf -nostartfiles -T ../source/app.lds \
./main.o \
./stm32f10x_i2c.o -lbios_la104 -L../../../os_library/build

arm-none-eabi-objdump -d -S output.elf > output.asm
arm-none-eabi-readelf -all output.elf > output.txt

find . -type f -name '*.o' -delete
find . -type f -name '*.d' -delete

../../../../tools/elfstrip/elfstrip output.elf 100i2ct.elf
1 change: 1 addition & 0 deletions system/apps_experiments/100_lowi2c/cp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cp build/100i2ct.elf /Volumes/LA104/100i2ct.elf
34 changes: 34 additions & 0 deletions system/apps_experiments/100_lowi2c/source/app.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
MEMORY
{
rom (rx) : ORIGIN = 0x0801ed00, LENGTH = 60K
ram (rwx) : ORIGIN = 0x20004800, LENGTH = 16K
null (rwx): ORIGIN = 0x00001000, LENGTH = 4K
}

/* _estack = ORIGIN(ram)+LENGTH(ram)-0x100; */

SECTIONS
{
.text : {
*(.entry)
*(.text*) /* Program code */
*(.rodata*) /* Read only data */
} >rom

.data : {
*(.data*) /* Data memory */
/* *(.dynamic*) */
} >ram AT >rom

.bss : {
*(.bss*) /* Zero-filled run time allocate data memory */
} >ram

.rel.plt : { *(.rel.plt) } > rom
.plt : { *(.plt) } > rom
.got : { *(.got.plt) *(.got) } > ram /* relocation fixed by memory write! */
.dynsym : { *(.dynsym) } > null
.dynstr : { *(.dynstr) } > null

}

187 changes: 187 additions & 0 deletions system/apps_experiments/100_lowi2c/source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#include <library.h>
#include "../../../os_host/source/framework/Console.h"
#include "../../../os_host/source/framework/SimpleApp.h"

extern "C" {
#include "stm32/stm32f10x_i2c.h"
#include "stm32/la104_i2c.h"
}


long timeout = 0;
void TimeoutReset(long duration)
{
timeout = BIOS::SYS::GetTick() + duration;
}
bool Timeout()
{
EVERY(500)
{
CONSOLE::Color(RGB565(b0b0b0));
CONSOLE::Print(".");
CONSOLE::Color(RGB565(ffffff));
}
return BIOS::SYS::GetTick() > timeout;
}

#define TIMEOUT(msg) if (Timeout()) { \
CONSOLE::Color(RGB565(ff0000)); \
CONSOLE::Print("Timeout: %s ", msg); \
CONSOLE::Color(RGB565(ffffff)); \
return false; \
}

bool I2C_check_presence(uint8_t HW_address)
{
HW_address <<= 1;

BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::Output);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P2, BIOS::GPIO::EMode::Output);
BIOS::GPIO::DigitalWrite(BIOS::GPIO::EPin::P1, true);
BIOS::GPIO::DigitalWrite(BIOS::GPIO::EPin::P2, true);
BIOS::SYS::DelayMs(100);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::I2c);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P2, BIOS::GPIO::EMode::I2c);
BIOS::SYS::DelayMs(100);

/*
// I2C_Cmd(I2Cx, DISABLE);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::Input);
BIOS::SYS::DelayMs(100);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::I2c);
// I2C_Cmd(I2Cx, ENABLE);
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
TimeoutReset(1000);
*/
/*
TimeoutReset(200);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))
{
if (Timeout())
{
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::Output);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P2, BIOS::GPIO::EMode::Output);
BIOS::GPIO::DigitalWrite(BIOS::GPIO::EPin::P1, true);
BIOS::GPIO::DigitalWrite(BIOS::GPIO::EPin::P2, true);
BIOS::SYS::DelayMs(100);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::I2c);
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P2, BIOS::GPIO::EMode::I2c);
BIOS::SYS::DelayMs(100);
CONSOLE::Print("[busy i2c workaround]");
// _ASSERT(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))
break;
}
} //TIMEOUT("1-busy");
*/
TimeoutReset(500);

// while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) TIMEOUT("1-busy");
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) TIMEOUT("2-start");
I2C_Send7bitAddress(I2Cx, HW_address, I2C_Direction_Transmitter);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) TIMEOUT("3-transmit");

// I2C_SendData(I2Cx, addr);
// while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) TIMEOUT("4-address");

//I2C_AcknowledgeConfig(I2Cx, DISABLE);

I2C_GenerateSTOP(I2Cx, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) TIMEOUT("5-stop");
return true;
}
/*
void I2C_burst_read(uint8_t HW_address, uint8_t addr, uint8_t n_data, uint8_t *data)
{
// <start><addr><ack><command><ack><start><addr><ack><data><nack><stop>
HW_address <<= 1;
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) q("a");
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) q("b");
I2C_Send7bitAddress(I2Cx, HW_address, I2C_Direction_Transmitter);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) q("c");
I2C_SendData(I2Cx, addr);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) q("d");
// I2C_GenerateSTOP(I2Cx, ENABLE);
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) q("e");
I2C_Send7bitAddress(I2Cx, HW_address, I2C_Direction_Receiver);
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) q("f");
I2C_AcknowledgeConfig(I2Cx, ENABLE);
while(n_data--) {
if(!n_data) I2C_AcknowledgeConfig(I2Cx, DISABLE);
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) q("g");
*data++ = I2C_ReceiveData(I2Cx);
}
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) q("h");
}
*/


uint32_t* gpioStatus = nullptr;

bool check()
{
if (*gpioStatus == 0)
{
return true;
}
else
CONSOLE::Print("[err:%d]", *gpioStatus);

*gpioStatus = 0;
return false;
}

void setup()
{
BIOS::GPIO::PinMode(BIOS::GPIO::EPin::P1, BIOS::GPIO::EMode::I2c);
gpioStatus = (uint32_t*)BIOS::SYS::GetAttribute(BIOS::SYS::EAttribute::GpioStatus);
}

void loop()
{
if (I2C_check_presence(0x40))
CONSOLE::Print("Good, ");
else
{
CONSOLE::Print("Bad, ");
}
BIOS::SYS::DelayMs(1000);
}

#ifdef _ARM
__attribute__((__section__(".entry")))
#endif
int _main(void)
{
APP::Init("I2C low level test");
APP::Status("P1: SCL, P2: SDA");

setup();

BIOS::KEY::EKey key;
while ((key = BIOS::KEY::GetKey()) != BIOS::KEY::EKey::Escape)
{
loop();
}
return 0;
}

void _HandleAssertion(const char* file, int line, const char* cond)
{
BIOS::DBG::Print("Assertion failed in ");
BIOS::DBG::Print(file);
BIOS::DBG::Print(" [%d]: %s\n", line, cond);
while (1);
}
Loading

0 comments on commit 47b1f4e

Please sign in to comment.