libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
logger_impl.h
Go to the documentation of this file.
1#pragma once
2#ifndef __DSY_LOGGER_IMPL_H
3#define __DSY_LOGGER_IMPL_H
4#include <unistd.h>
5#include <cstdint>
6#include <cassert>
7#include "hid/usb.h"
8#include "per/uart.h"
9#include "sys/system.h"
10#include "daisy_core.h"
11
12
13namespace daisy
14{
25
30template <LoggerDestination dest>
32{
33 public:
36 static void Init() {}
37
40 static bool Transmit(const void* buffer, size_t bytes) { return true; }
41};
42
43
46template <>
48{
49 public:
52 static void Init()
53 {
57 static_assert(1u == sizeof(usb_handle_), "UsbHandle is not static");
58 usb_handle_.Init(UsbHandle::FS_INTERNAL);
59 }
60
63 static bool Transmit(const void* buffer, size_t bytes)
64 {
66 == usb_handle_.TransmitInternal((uint8_t*)buffer, bytes);
67 }
68
69 protected:
73};
74
75
78template <>
80{
81 public:
84 static void Init()
85 {
89 static_assert(1u == sizeof(usb_handle_), "UsbHandle is not static");
90 usb_handle_.Init(UsbHandle::FS_EXTERNAL);
91 }
92
95 static bool Transmit(const void* buffer, size_t bytes)
96 {
98 == usb_handle_.TransmitExternal((uint8_t*)buffer, bytes);
99 }
100
101 protected:
105};
106
107
110template <>
112{
113 public:
116 static void Init() {}
117
120 static bool Transmit(const void* buffer, size_t bytes)
121 {
122 write(STDOUT_FILENO, buffer, bytes);
123 return true;
124 }
125};
126
128template <>
130{
131 public:
132 struct Config
133 {
136 uint32_t baudrate = 115200;
137 };
138
140 static void Configure(const Config cfg) { config_ = cfg; }
141
142
144 static void Init()
145 {
146 if(!config_.tx_pin.IsValid())
147 return;
148 UartHandler::Config uart_cfg;
150 uart_cfg.periph = config_.uart;
151 uart_cfg.pin_config.tx = config_.tx_pin;
152 uart_cfg.baudrate = config_.baudrate;
153 uart_.Init(uart_cfg);
154 }
155
157 static bool Transmit(const void* buffer, size_t bytes)
158 {
159 return uart_.BlockingTransmit((uint8_t*)(buffer), bytes, 20)
161 }
162
163
164 protected:
167};
168
169
170} /* namespace daisy */
171
172#endif //__DSY_LOGGER_IMPL_H
Interface for initializing and using the USB Peripherals on the daisy.
Definition usb.h:19
@ FS_EXTERNAL
Definition usb.h:32
@ FS_INTERNAL
Definition usb.h:31
static bool Transmit(const void *buffer, size_t bytes)
Definition logger_impl.h:95
static void Init()
Definition logger_impl.h:84
static UsbHandle usb_handle_
Definition logger_impl.h:104
static void Init()
Definition logger_impl.h:52
static bool Transmit(const void *buffer, size_t bytes)
Definition logger_impl.h:63
static UsbHandle usb_handle_
Definition logger_impl.h:72
static bool Transmit(const void *buffer, size_t bytes)
Definition logger_impl.h:120
static void Init()
Definition logger_impl.h:116
static void Init()
Definition logger_impl.h:144
static UartHandler uart_
Definition logger_impl.h:166
static Config config_
Definition logger_impl.h:165
static bool Transmit(const void *buffer, size_t bytes)
Definition logger_impl.h:157
static void Configure(const Config cfg)
Definition logger_impl.h:140
Logging I/O underlying implementation.
Definition logger_impl.h:32
static void Init()
Definition logger_impl.h:36
static bool Transmit(const void *buffer, size_t bytes)
Definition logger_impl.h:40
Definition uart.h:27
Hardware defines and helpers for daisy field platform.
Definition index.h:2
LoggerDestination
Definition logger_impl.h:18
@ LOGGER_INTERNAL
Definition logger_impl.h:20
@ LOGGER_EXTERNAL
Definition logger_impl.h:21
@ LOGGER_UART
Definition logger_impl.h:23
@ LOGGER_SEMIHOST
Definition logger_impl.h:22
@ LOGGER_NONE
Definition logger_impl.h:19
Definition logger_impl.h:133
UartHandler::Config::Peripheral uart
Definition logger_impl.h:134
Pin tx_pin
Definition logger_impl.h:135
representation of hardware port/pin combination
Definition daisy_core.h:193
Definition uart.h:30
Pin tx
Definition uart.h:75
Mode mode
Definition uart.h:91
Peripheral periph
Definition uart.h:88
struct daisy::UartHandler::Config::@20 pin_config
uint32_t baudrate
Definition uart.h:93
Peripheral
Definition uart.h:32