Files
aligned
app
arrayvec
as_slice
bare_metal
byteorder
cfg_if
cortex_m
cortex_m_rt
cstr_core
cty
druid
druid_shell
embedded_graphics
embedded_hal
generic_array
hash32
heapless
introsort
kurbo
libchip8
libm
log
memchr
mynewt
nb
num_traits
piet
piet_common
piet_embedded_graphics
r0
st7735_lcd
stable_deref_trait
typenum
unicode_segmentation
vcell
void
volatile_register
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
//! Display messages on Arm Semihosting Console (via OpenOCD)

///  Display message `msg` on the Arm Semihosting console (via OpenOCD).
#[cfg(feature = "dispatch")]  //  With dispatch...
pub fn print(msg: &str) {
    //  Call the Semihosting Console API, which is unsafe.
    let buf = msg.as_ptr();
    let len = msg.len() as u32;

    //  TODO: Dispatch the Mynewt C function `console_buffer`.
    //  TODO: Use a procedural macro to compute the hash of function name `console_buffer`.
    let hash = 0;  //  TODO
    //  TODO: Lookup the dispatch address of `console_buffer`.
    let _addr = get_dispatch_address(hash);
    //  TODO: Call the `console_buffer` function using the dispatch address.
    unsafe { console_buffer(buf, len); }
}

/// Return the Dispatch Address for the OS function whose function name hashed is `hash`
#[cfg(feature = "dispatch")]  //  With dispatch...
pub fn get_dispatch_address(_hash: u32) -> u32 {
    //  TODO: Lookup the Dispatch Table for the hash of function name
    0
}

///  Display message `msg` on the Arm Semihosting console (via OpenOCD).
#[cfg(not(feature = "dispatch"))]  //  Previously without dispatch...
pub fn print(msg: &str) {
    //  Call the Semihosting Console API, which is unsafe.
    unsafe { console_buffer(msg.as_ptr(), msg.len() as u32); }
}

///  Display message `msg` on the Arm Semihosting console (via OpenOCD).
pub fn print_strn(msg: &crate::Strn) {
    //  Call the Semihosting Console API, which is unsafe.
    unsafe { console_buffer(msg.as_ptr(), msg.len() as u32); }
}

///  Add the string to the output buffer.
pub fn buffer(msg: &str) {
    //  Call the Semihosting Console API, which is unsafe.
    unsafe { console_buffer(msg.as_ptr(), msg.len() as u32); }
}

///  Write a byte in hexadecimal to the output buffer.
///  C API: `void console_printhex(uint8_t v)`
pub fn printhex(v: u8) {
    unsafe { console_printhex(v); }
}

///  Write an int to the output buffer.
///  C API: `void console_printint(int i)`
pub fn printint(v: i32) {
    unsafe { console_printint(v); }
}

///  Write a float to the output buffer, with 2 decimal places.
pub fn printfloat(v: f32) {
    unsafe { console_printfloat(v); }
}

///  Write a double to the output buffer, with 6 decimal places.
pub fn printdouble(v: f64) {
    unsafe { console_printdouble(v); }
}

///  Write "length" number of bytes from "buffer" to the output buffer in hex format.
pub fn dump(buffer: *const u8, len: u32) {
    unsafe { console_dump(buffer, len); }
}

///  Flush the output buffer to the console.
pub fn flush() {
    unsafe { console_flush(); }
}

///  Import the custom Mynewt library for displaying messages on the Arm Semihosting Console (via OpenOCD).
///  The library is located at `libs/semihosting_console`
#[link(name = "libs_semihosting_console")]  //  Functions below are located in the Mynewt build output `libs_semihosting_console.a`
extern {
    ///  Add the string to the output buffer.
    ///  C API: `void console_buffer(const char *buffer, unsigned int length)`
    fn console_buffer(buffer: *const u8, length: u32);  

    ///  Write a byte in hexadecimal to the output buffer.
    ///  C API: `void console_printhex(uint8_t v)`
    fn console_printhex(v: u8);  

    ///  Write an int i to the output buffer.
    ///  C API: `void console_printint(int i)`
    fn console_printint(i: i32);

    ///  Write a float to the output buffer, with 2 decimal places.
    ///  C API: `void console_printfloat(float f)`
    fn console_printfloat(f: f32);

    ///  Write a double to the output buffer, with 6 decimal places.
    ///  C API: `void console_printdouble(double d)`
    fn console_printdouble(d: f64);

    ///  Write "length" number of bytes from "buffer" to the output buffer in hex format.
    ///  C API: `void console_dump(const uint8_t *buffer, unsigned int len)`
    fn console_dump(buffer: *const u8, len: u32);  

    ///  Flush the output buffer to the console.
    ///  C API: `void console_flush(void)`
    fn console_flush();  //  Flush the output buffer to the console.
}