20 changed files with 384 additions and 106 deletions
@ -0,0 +1,16 @@ |
|||||
|
#include "dizzy.hh" |
||||
|
|
||||
|
ld::DaisySeed seed{}; |
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
seed.Init(); |
||||
|
ld::DaisySeed::StartLog(true); |
||||
|
ld::DaisySeed::PrintLine("booting..."); |
||||
|
dz::CLI::init(seed); |
||||
|
|
||||
|
while (true) { |
||||
|
dz::CLI::process(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,58 @@ |
|||||
|
#include "dizzy.hh" |
||||
|
|
||||
|
ld::DaisySeed seed{}; |
||||
|
|
||||
|
struct Time { |
||||
|
Time() |
||||
|
{ |
||||
|
msec = seed.system.GetNow(); |
||||
|
usec = seed.system.GetUs(); |
||||
|
tick = seed.system.GetTick(); |
||||
|
} |
||||
|
|
||||
|
u32 msec; |
||||
|
u32 usec; |
||||
|
u32 tick; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
std::string to_string(Time &obj) |
||||
|
{ |
||||
|
std::string ret{ "Time: " }; |
||||
|
ret += std::to_string(obj.msec); |
||||
|
ret += " / "; |
||||
|
ret += std::to_string(obj.usec); |
||||
|
ret += " / "; |
||||
|
ret += std::to_string(obj.tick); |
||||
|
return ret; |
||||
|
} |
||||
|
|
||||
|
void print_uptime(u32 time) |
||||
|
{ |
||||
|
Time t{}; |
||||
|
std::string str{ to_string(t) + "\n\r" }; |
||||
|
dz::Console::tx(str.c_str(), str.size()); |
||||
|
} |
||||
|
|
||||
|
dz::PeriodicTaskCT<print_uptime, 1000> task1{}; |
||||
|
|
||||
|
int main(void) |
||||
|
{ |
||||
|
seed.Init(); |
||||
|
|
||||
|
dz::Console::init(); |
||||
|
while (!dz::Console::has_next()) {}; |
||||
|
|
||||
|
std::string motd{ "dizzy console\n" }; |
||||
|
dz::Console::tx(motd.c_str(), motd.size()); |
||||
|
|
||||
|
while (true) { |
||||
|
Time time_mainloop_begin{}; |
||||
|
while (dz::Console::has_next()) { |
||||
|
char b = dz::Console::rx(); |
||||
|
dz::Console::tx(&b, 1); |
||||
|
} |
||||
|
|
||||
|
task1.run_pending(time_mainloop_begin.msec); |
||||
|
} |
||||
|
} |
@ -0,0 +1,58 @@ |
|||||
|
#ifndef HECK_DIZZY_CLI_HH |
||||
|
#define HECK_DIZZY_CLI_HH |
||||
|
|
||||
|
#include <map> |
||||
|
#include <functional> |
||||
|
#include "dizzy_types.hh" |
||||
|
#include "console.hh" |
||||
|
#include <string> |
||||
|
|
||||
|
|
||||
|
namespace Heck::Dizzy { |
||||
|
namespace CLI { |
||||
|
using command_function = std::function<void()>; |
||||
|
|
||||
|
inline std::string command_buf; |
||||
|
inline std::map<std::string, command_function> command_table; |
||||
|
|
||||
|
inline void command_test() |
||||
|
{ |
||||
|
ld::DaisySeed::PrintLine("test"); |
||||
|
} |
||||
|
|
||||
|
inline void init(ld::DaisySeed& seed) |
||||
|
{ |
||||
|
Console::init(); |
||||
|
ld::DaisySeed::PrintLine("Dizzy-CLI"); |
||||
|
ld::DaisySeed::Print("> "); |
||||
|
command_table.emplace("test", &command_test); |
||||
|
} |
||||
|
|
||||
|
inline void process() |
||||
|
{ |
||||
|
while (Console::has_next()) { |
||||
|
u8 c = Console::rx(); |
||||
|
if (c == 13) { //Enter
|
||||
|
//echo
|
||||
|
ld::DaisySeed::PrintLine(""); |
||||
|
if (!command_buf.empty()) { |
||||
|
command_function func = command_table[command_buf]; |
||||
|
if (func) { |
||||
|
ld::DaisySeed::PrintLine("running command: %s", command_buf.data()); |
||||
|
func(); |
||||
|
} else { |
||||
|
ld::DaisySeed::PrintLine("error: unknown command: %s", command_buf.data()); |
||||
|
} |
||||
|
command_buf.clear(); |
||||
|
} |
||||
|
ld::DaisySeed::Print("> "); |
||||
|
} else { |
||||
|
//echo
|
||||
|
ld::DaisySeed::Print("%c", c); |
||||
|
command_buf.push_back(static_cast<char>(c)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} // namespace CLI
|
||||
|
} // namespace Heck::Dizzy
|
||||
|
#endif |
@ -0,0 +1,52 @@ |
|||||
|
#include "console.hh" |
||||
|
#include <deque> |
||||
|
#include "hid/usb.h" |
||||
|
|
||||
|
namespace Heck::Dizzy { |
||||
|
namespace Console { |
||||
|
|
||||
|
struct Session { |
||||
|
std::deque<char> rx_buff; |
||||
|
daisy::UsbHandle usb_handle; |
||||
|
}; |
||||
|
|
||||
|
static Session session_{}; |
||||
|
|
||||
|
|
||||
|
extern "C" void usb_rx_callback(u8* buff, u32* length) |
||||
|
{ |
||||
|
if (buff && length) { |
||||
|
for (u32 i = 0; i < *length; i++) { |
||||
|
session_.rx_buff.emplace_back(buff[i]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void init() |
||||
|
{ |
||||
|
session_.usb_handle.Init(daisy::UsbHandle::FS_INTERNAL); |
||||
|
session_.usb_handle.SetReceiveCallback( |
||||
|
usb_rx_callback, |
||||
|
daisy::UsbHandle::UsbPeriph::FS_INTERNAL); |
||||
|
} |
||||
|
|
||||
|
bool has_next() |
||||
|
{ |
||||
|
return !session_.rx_buff.empty(); |
||||
|
} |
||||
|
|
||||
|
char rx() |
||||
|
{ |
||||
|
char ret{ session_.rx_buff.front() }; |
||||
|
session_.rx_buff.pop_front(); |
||||
|
return ret; |
||||
|
} |
||||
|
|
||||
|
bool tx(const char* buffer, size_t len) |
||||
|
{ |
||||
|
return daisy::UsbHandle::Result::OK == |
||||
|
session_.usb_handle.TransmitInternal((uint8_t*)buffer, len); |
||||
|
} |
||||
|
|
||||
|
} // namespace Console
|
||||
|
} // namespace Heck::Dizzy
|
@ -0,0 +1,15 @@ |
|||||
|
#ifndef HECK_DIZZY_CONSOLE_HH |
||||
|
#define HECK_DIZZY_CONSOLE_HH |
||||
|
|
||||
|
#include "dizzy_types.hh" |
||||
|
|
||||
|
namespace Heck::Dizzy { |
||||
|
namespace Console { |
||||
|
void init(); |
||||
|
bool has_next(); |
||||
|
char rx(); |
||||
|
bool tx(const char *buffer, size_t len); |
||||
|
} // namespace Console
|
||||
|
} // namespace Heck::Dizzy
|
||||
|
|
||||
|
#endif |
@ -0,0 +1,12 @@ |
|||||
|
#ifndef HECK_DIZZY_HH |
||||
|
#define HECK_DIZZY_HH |
||||
|
|
||||
|
#include "dizzy_types.hh" |
||||
|
#include "utils.hh" |
||||
|
#include "console.hh" |
||||
|
#include "cli.hh" |
||||
|
#include "density.hh" |
||||
|
|
||||
|
namespace dz = Heck::Dizzy; |
||||
|
|
||||
|
#endif |
@ -0,0 +1,16 @@ |
|||||
|
#ifndef HECK_DIZZY_TYPES_HH |
||||
|
#define HECK_DIZZY_TYPES_HH |
||||
|
|
||||
|
#include "heck_types.hh" |
||||
|
#include "daisy_seed.h" |
||||
|
#include "daisysp.h" |
||||
|
|
||||
|
namespace ld = daisy; |
||||
|
namespace dsp = daisysp; |
||||
|
using namespace Heck::Types; |
||||
|
|
||||
|
namespace Heck::Dizzy { |
||||
|
using Samplerate = ld::SaiHandle::Config::SampleRate; |
||||
|
} // namespace Heck::Dizzy
|
||||
|
|
||||
|
#endif |
@ -0,0 +1,22 @@ |
|||||
|
#ifndef HECK_TYPES_HH |
||||
|
#define HECK_TYPES_HH |
||||
|
|
||||
|
#include <cstdint> |
||||
|
|
||||
|
namespace Heck::Types { |
||||
|
// fundamental types
|
||||
|
using u8 = uint8_t; |
||||
|
using u16 = uint16_t; |
||||
|
using u32 = uint32_t; |
||||
|
using u64 = uint64_t; |
||||
|
|
||||
|
using i8 = int8_t; |
||||
|
using i16 = int16_t; |
||||
|
using i32 = int32_t; |
||||
|
using i64 = int64_t; |
||||
|
|
||||
|
using f32 = float; |
||||
|
using f64 = double; |
||||
|
} // namespace Heck::Types
|
||||
|
|
||||
|
#endif |
@ -1,36 +0,0 @@ |
|||||
#ifndef HECK_DAISY_TYPES_HH |
|
||||
#define HECK_DAISY_TYPES_HH |
|
||||
|
|
||||
#include <cstdint> |
|
||||
#include "daisy_seed.h" |
|
||||
#include "daisysp.h" |
|
||||
|
|
||||
namespace Heck { |
|
||||
namespace Types { |
|
||||
// fundamental types
|
|
||||
using u8 = uint8_t; |
|
||||
using u16 = uint16_t; |
|
||||
using u32 = uint32_t; |
|
||||
using u64 = uint64_t; |
|
||||
|
|
||||
using i8 = int8_t; |
|
||||
using i16 = int16_t; |
|
||||
using i32 = int32_t; |
|
||||
using i64 = int64_t; |
|
||||
|
|
||||
using f32 = float; |
|
||||
using f64 = double; |
|
||||
} |
|
||||
|
|
||||
using namespace Types; |
|
||||
// namespace aliases
|
|
||||
namespace ld = daisy; |
|
||||
namespace dsp = daisysp; |
|
||||
|
|
||||
// type aliases from libs
|
|
||||
using Samplerate = ld::SaiHandle::Config::SampleRate; |
|
||||
|
|
||||
} // namespace Heck
|
|
||||
|
|
||||
|
|
||||
#endif |
|
Loading…
Reference in new issue