├── .clang-format ├── .gitignore ├── .gitmodules ├── Makefile ├── Pipfile ├── Pipfile.lock ├── README.md ├── apps ├── hello_world │ ├── Makefile │ └── source │ │ └── main.cpp └── periph_test │ ├── Makefile │ ├── mbed_app.json │ └── source │ ├── main.cpp │ ├── ptime_accel.cpp │ └── ptime_accel.h ├── drivers ├── Adafruit_GFX │ ├── Adafruit_GFX.cpp │ ├── Adafruit_GFX.h │ ├── README.md │ └── glcdfont.h ├── Adafruit_ST7789 │ ├── Adafruit_ST7789.cpp │ ├── Adafruit_ST7789.h │ └── README.md ├── BMA42x_Accelerometer │ ├── README.md │ ├── bma4.c │ ├── bma4.h │ ├── bma421.c │ ├── bma421.h │ ├── bma423.c │ ├── bma423.h │ └── bma4_defs.h ├── CST0xx_TouchPad │ ├── CST0xx_TouchPad.cpp │ └── CST0xx_TouchPad.h ├── HRS3300_HeartRateSensor │ ├── HRS3300_HeartRateSensor.cpp │ └── HRS3300_HeartRateSensor.h ├── SEGGER_RTT_V654c │ ├── Examples │ │ ├── Main_RTT_InputEchoApp.c │ │ ├── Main_RTT_MenuApp.c │ │ ├── Main_RTT_PrintfTest.c │ │ └── Main_RTT_SpeedTestApp.c │ ├── License.txt │ ├── README.txt │ ├── RTT │ │ ├── SEGGER_RTT.c │ │ ├── SEGGER_RTT.h │ │ ├── SEGGER_RTT_ASM_ARMv7M.S │ │ ├── SEGGER_RTT_Conf.h │ │ └── SEGGER_RTT_printf.c │ └── Syscalls │ │ ├── SEGGER_RTT_Syscalls_GCC.c │ │ ├── SEGGER_RTT_Syscalls_IAR.c │ │ ├── SEGGER_RTT_Syscalls_KEIL.c │ │ └── SEGGER_RTT_Syscalls_SES.c └── mbed-rtt │ ├── mbed-rtt.cpp │ └── mbed-rtt.h ├── media └── pixel-painting.gif └── targets ├── TARGET_NORDIC └── TARGET_NRF5x │ └── TARGET_NRF52 │ └── TARGET_MCU_NRF52832 │ └── TARGET_PINETIME_DEV_KIT │ ├── PinNames.h │ └── device.h └── custom_targets.json /.clang-format: -------------------------------------------------------------------------------- 1 | UseTab: Never 2 | IndentWidth: 4 3 | BreakBeforeBraces: Allman 4 | AllowShortIfStatementsOnASingleLine: false 5 | IndentCaseLabels: false 6 | ColumnLimit: 100 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "modules/mbed-os"] 2 | path = modules/mbed-os 3 | url = https://github.com/ARMmbed/mbed-os.git 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | MBED_PYTHON = python3 3 | 4 | MBED_TOOLS_PATH = foobar 5 | MBED_TOOLCHAIN = GCC_ARM 6 | 7 | ifeq ($(PROFILE),) 8 | PROFILE := $(MBED_PINETIME_PATH)/modules/mbed-os/tools/profiles/debug.json 9 | endif 10 | 11 | PROFILE_NAME = $(basename $(notdir $(PROFILE))) 12 | 13 | 14 | help: 15 | @echo "This is not the Makefile you're looking for." 16 | 17 | 18 | build: FORCE 19 | $(MBED_PYTHON) $(MBED_PINETIME_PATH)/modules/mbed-os/tools/make.py \ 20 | -t $(MBED_TOOLCHAIN) -m $(MBED_TARGET) \ 21 | --custom-targets $(MBED_PINETIME_PATH)/targets \ 22 | --profile $(PROFILE) \ 23 | $(MBED_SOURCES) \ 24 | --build $(MBED_PINETIME_PATH)/apps/$(APP_NAME)/build/$(PROFILE_NAME) \ 25 | --app-config mbed_app.json \ 26 | --artifact-name $(APP_NAME) 27 | 28 | bootstrap-python: 29 | pipenv install -r modules/mbed-os/requirements.txt 30 | pipenv install --skip-lock 31 | 32 | FORCE: -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | 8 | [packages] 9 | # Mbed required packages 10 | colorama = "==0.3.9" 11 | urllib3 = {extras = ["secure"],version = "==1.24.2"} 12 | junit-xml = "==1.8" 13 | jsonschema = "==2.6.0" 14 | future = "==0.16.0" 15 | six = "==1.12.0" 16 | mbed-cloud-sdk = "<2.1,>=2.0.6" 17 | requests = ">=2.20,<2.21" 18 | idna = "<2.8,>=2" 19 | pyserial = "<=3.4,>=3" 20 | mbed-ls = ">=1.5.1,<1.8" 21 | mbed-host-tests = ">=1.4.4,<1.6" 22 | mbed-greentea = ">=0.2.24,<1.8" 23 | beautifulsoup4 = "<=4.6.3,>=4" 24 | pyelftools = "<=0.25,>=0.24" 25 | manifest-tool = "==1.5.2" 26 | icetea = ">=1.2.1,<1.3" 27 | pycryptodome = ">=3.7.2,<=3.7.3" 28 | pyusb = "<2.0.0,>=1.0.0" 29 | hidapi = {markers = "platform_system != 'Linux'",version = ">=0.7.99,<0.8.0"} 30 | cmsis-pack-manager = "<0.3.0,>=0.2.3" 31 | pywin32 = {markers = "platform_system == 'Windows'",version = "==224"} 32 | psutil = "==5.6.2" 33 | cryptography = "<2.5,>=2.4.x" 34 | click = ">=7.0,<7.1" 35 | PrettyTable = "==0.7.2" 36 | PyYAML = "==4.2b1" 37 | Jinja2 = ">=2.10.1,<2.11" 38 | IntelHex = ">=1.3,<=2.2.1" 39 | WMI = {markers = "platform_system == 'Windows'",version = "==1.4.9"} 40 | 41 | # Other useful packages 42 | black = "*" 43 | 44 | [requires] 45 | python_version = "3.7" 46 | 47 | [pipenv] 48 | allow_prereleases = true 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Animated GIF of Pinetime demo](media/pixel-painting.gif) 2 | 3 | # Getting Started 4 | 5 | > These instructions are macOS centric right now, but the Mbed toolchain will work on Mac, Windows, and Linux. Improvments to these instructions are welcome. 6 | 7 | Install the arm-eabi-none toolchain 8 | ``` 9 | brew tap PX4/homebrew-px4 10 | brew install PX4/homebrew-px4/gcc-arm-none-eabi-63 11 | ``` 12 | 13 | Optionally, install `nrfjprog` 14 | ``` 15 | brew cask install nordic-nrf-command-line-tools 16 | ``` 17 | 18 | Checkout all submodules `git submodule update --init --recursive`. 19 | 20 | Install all the Python packages required for Mbed. Your options are: 21 | - Install from the Pipfile. `pipenv install` 22 | - Install from Mbed requirements.txt `pip install -r modules/mbed-os/requirements.txt` 23 | 24 | To use the Makefiles, you must set the environment variable `MBED_PINETIME_PATH` to the root of the repository. If anyone has ideas on how to not need this or otherwise improve the build system, let me know. 25 | 26 | 27 | 28 | # Development Notes 29 | 30 | - [x] BMA421 Accelerometer 31 | - [-] HRS3300 Heart Rate Sensor 32 | - [x] Hynitron CST816S Touch Pad 33 | - [-] Sitronix ST7789V LCD Driver 34 | - [x] Macronix SPI Flash 35 | - [x] Vibrator 36 | - [x] LED backlight 37 | - [x] ADC Battery Voltage Sense 38 | - [ ] Physical button 39 | 40 | ### I2C 41 | 00> 0x15 Touchpad 42 | - Only responds after a touch event. 43 | - At 100khz, Limit of read from register 0x00 after a touch event is 190-195ish bytes. This is probably due to the chip going back to sleep. 44 | 45 | 00> 0x18 ACK Accelerometer 46 | - BMA421 -- Not a public avalible chip, therefore no publicly availible drivers. 47 | - Similar to BMA423 48 | - Seems to require binary blob on startup (chip firmware?) 49 | 50 | 00> 0x44 ACK HALS3300 Heart Rate Sensor 51 | - Datasheet is OK 52 | - Resolution was set to 16bits 0x08 53 | - Gain was set to 1 0x02 54 | 55 | ### SPI 56 | Flash: 57 | - SPI flash is now working with Mbed SPIF driver 58 | - Needed to be "reset" by letting the battery die 59 | - 4194304 bytes 60 | 61 | Display: 62 | - Display needs mode 3 SPI? 63 | - https://www.allaboutcircuits.com/technical-articles/spi-serial-peripheral-interface/ 64 | - Got it sort-of working with Mbed ports of the Adafruit GFX libraries. 65 | - Still work to be done here 66 | 67 | I can't get the physical button to work for the life of me. Someone please help 😂 68 | -------------------------------------------------------------------------------- /apps/hello_world/Makefile: -------------------------------------------------------------------------------- 1 | APP_NAME = hello_world 2 | MBED_TARGET = TARGET_PINETIME_DEV_KIT 3 | 4 | MBED_SOURCES += --source $(MBED_PINETIME_PATH)/modules/mbed-os/ \ 5 | --source $(MBED_PINETIME_PATH)/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_PINETIME_DEV_KIT/ \ 6 | --source source/ \ 7 | --source $(MBED_PINETIME_PATH)/drivers/SEGGER_RTT_V654c/RTT/ \ 8 | 9 | include ../../Makefile -------------------------------------------------------------------------------- /apps/hello_world/source/main.cpp: -------------------------------------------------------------------------------- 1 | #include "SEGGER_RTT.h" 2 | 3 | #include "mbed.h" 4 | 5 | 6 | int main() 7 | { 8 | SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL); 9 | SEGGER_RTT_WriteString(0, "Hello World!\r\n\r\n"); 10 | int x = 5; 11 | while(true) 12 | { 13 | SEGGER_RTT_printf(0, "printf Test: %%d, x : %d.\r\n", x); 14 | x++; 15 | ThisThread::sleep_for(1000); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /apps/periph_test/Makefile: -------------------------------------------------------------------------------- 1 | APP_NAME = periph_test 2 | MBED_TARGET = TARGET_PINETIME_DEV_KIT 3 | 4 | PROFILE := $(MBED_PINETIME_PATH)/modules/mbed-os/tools/profiles/release.json 5 | 6 | MBED_SOURCES += --source $(MBED_PINETIME_PATH)/modules/mbed-os/ \ 7 | --source $(MBED_PINETIME_PATH)/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_PINETIME_DEV_KIT/ \ 8 | --source source/ \ 9 | --source $(MBED_PINETIME_PATH)/drivers/SEGGER_RTT_V654c/RTT/ \ 10 | --source $(MBED_PINETIME_PATH)/drivers/mbed-rtt \ 11 | --source $(MBED_PINETIME_PATH)/drivers/BMA42x_Accelerometer \ 12 | --source $(MBED_PINETIME_PATH)/drivers/HRS3300_HeartRateSensor \ 13 | --source $(MBED_PINETIME_PATH)/drivers/CST0xx_TouchPad \ 14 | --source $(MBED_PINETIME_PATH)/drivers/Adafruit_ST7789 \ 15 | --source $(MBED_PINETIME_PATH)/drivers/Adafruit_GFX 16 | 17 | 18 | include ../../Makefile -------------------------------------------------------------------------------- /apps/periph_test/mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "macros": [], 3 | "target_overrides": { 4 | "*": { 5 | "mbed-trace.enable": 1 6 | }, 7 | "TARGET_PINETIME_DEV_KIT": { 8 | "spif-driver.SPI_MOSI": "SPI_MOSI", 9 | "spif-driver.SPI_MISO": "SPI_MISO", 10 | "spif-driver.SPI_CLK": "SPI_SCK", 11 | "spif-driver.SPI_CS": "SPI_CS_FLASH", 12 | "spif-driver.SPI_FREQ": "8000000", 13 | "spif-driver.debug": 1 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /apps/periph_test/source/main.cpp: -------------------------------------------------------------------------------- 1 | #include "BlockDevice.h" 2 | #include "drivers/AnalogIn.h" 3 | #include "drivers/DigitalIn.h" 4 | #include "drivers/DigitalOut.h" 5 | #include "drivers/I2C.h" 6 | #include "drivers/InterruptIn.h" 7 | #include "events/Event.h" 8 | #include "events/EventQueue.h" 9 | #include "platform/Callback.h" 10 | #include "rtos/Mutex.h" 11 | #include "rtos/ThisThread.h" 12 | 13 | #include "Adafruit_ST7789.h" 14 | #include "CST0xx_TouchPad.h" 15 | #include "HRS3300_HeartRateSensor.h" 16 | #include "ptime_accel.h" 17 | 18 | #include "mbed-rtt.h" 19 | 20 | #include 21 | 22 | #include "mbed-trace/mbed_trace.h" 23 | #define TRACE_GROUP "MAIN" 24 | 25 | namespace mbed 26 | { 27 | FileHandle *mbed_override_console(int fd) 28 | { 29 | static SeggerRTT rtt; 30 | return &rtt; 31 | } 32 | } // namespace mbed 33 | 34 | void on_touch_event(struct CST0xx_TouchPad::ts_event event); 35 | uint16_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 36 | void set_backlight(uint8_t light_level); 37 | void task_500ms(struct bma4_dev *dev); 38 | void touchpad_interrupt_handler(); 39 | void main_button_on_rise(); 40 | void main_button_on_fall(); 41 | 42 | events::EventQueue event_queue; 43 | 44 | mbed::DigitalOut vibrator(PIN_VIBRATOR_OUT); 45 | mbed::DigitalOut backlight_high(LCD_BACKLIGHT_HIGH); 46 | mbed::DigitalOut backlight_mid(LCD_BACKLIGHT_MID); 47 | mbed::DigitalOut backlight_low(LCD_BACKLIGHT_LOW); 48 | mbed::AnalogIn battery_voltage(BATTERY_VOLTAGE); 49 | mbed::DigitalIn charge_indication(PIN_CHARGE_INDICATION_IN); 50 | mbed::InterruptIn touchpad_interrupt(PIN_TOUCHPAD_INTERRUPT); 51 | mbed::InterruptIn main_button_interrupt(PIN_PUSH_BUTTON_OUT); 52 | 53 | mbed::DigitalOut spi_flash_cs(SPI_CS_FLASH); 54 | 55 | mbed::I2C i2c(I2C_SDA, I2C_SCL); 56 | HRS3300_HeartRateSensor hrs(&i2c); 57 | CST0xx_TouchPad touch_pad(&i2c, callback(on_touch_event)); 58 | 59 | Adafruit_ST7789 display(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS_LCD, PIN_LCD_RS_OUT, PIN_LCD_RESET_OUT); 60 | 61 | static rtos::Mutex trace_mutex; 62 | static void trace_mutex_wait() { trace_mutex.lock(); } 63 | static void trace_mutex_release() { trace_mutex.unlock(); } 64 | 65 | int main() 66 | { 67 | 68 | mbed_trace_mutex_wait_function_set(trace_mutex_wait); 69 | mbed_trace_mutex_release_function_set(trace_mutex_release); 70 | mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_COLOR); 71 | mbed_trace_init(); 72 | 73 | tr_info("Booting..."); 74 | vibrator = true; // Turns the vibrator off 75 | set_backlight(6); // Turn the backlight on 76 | 77 | mbed::BlockDevice *bd = mbed::BlockDevice::get_default_instance(); 78 | tr_info("BD init returned %i", bd->init()); 79 | tr_info("BD Size %lld.", bd->size()); 80 | 81 | i2c.frequency(400000); 82 | 83 | hrs.set_enable(HRS3300_HeartRateSensor::HRS_ENABLE, 84 | HRS3300_HeartRateSensor::HRS_WAIT_TIME_400ms); 85 | 86 | struct bma4_dev bma; 87 | 88 | ptime_accel_init(&bma, &i2c); 89 | 90 | tr_info("display init"); 91 | display.init(); 92 | tr_info("fillScreen"); 93 | display.fillScreen(0x07E0); 94 | 95 | display.setTextSize(2); 96 | display.setCursor(0, 0); 97 | display.setTextColor(0xFFFF, 0x0000); 98 | display.printf("SPIF Size: %lluB \r\n", bd->size()); 99 | 100 | event_queue.call_every(500, task_500ms, &bma); 101 | touchpad_interrupt.fall(event_queue.event(&touch_pad, &CST0xx_TouchPad::handle_interrupt)); 102 | main_button_interrupt.mode(PullNone); 103 | main_button_interrupt.rise(event_queue.event(main_button_on_rise)); 104 | main_button_interrupt.fall(event_queue.event(main_button_on_fall)); 105 | 106 | event_queue.dispatch_forever(); 107 | } 108 | 109 | void task_500ms(struct bma4_dev *bma) 110 | { 111 | float battery_voltage_v = (battery_voltage.read() * 3.3) * 2; 112 | struct bma4_accel data; 113 | int16_t rslt = bma4_read_accel_xyz(&data, bma); 114 | if (rslt) 115 | { 116 | ptime_accel_print_rslt(rslt); 117 | } 118 | 119 | display.setTextSize(2); 120 | display.setCursor(0, 40); 121 | display.setTextColor(0xFFFF, 0x0000); 122 | display.printf("Batt: %f \r\n", battery_voltage_v); 123 | 124 | if (charge_indication) 125 | { 126 | display.printf("Not Charging.\r\n"); 127 | } 128 | else 129 | { 130 | display.printf("Charging. \r\n"); 131 | } 132 | 133 | uint32_t hrs_val = hrs.read_heart_rate_sensor(); 134 | uint32_t als_val = hrs.read_ambient_light_sensor(); 135 | 136 | display.printf("HRS: %li \r\n", hrs_val); 137 | display.printf("ALS: %li \r\n", als_val); 138 | 139 | display.printf("X: %i \r\n", data.x); 140 | display.printf("Y: %i \r\n", data.y); 141 | display.printf("Z: %i \r\n", data.z); 142 | 143 | tr_info("Batt Volt: %f. Accel Data: %i, %i, %i. HRS: %lu. ALS: %lu.", battery_voltage_v, data.x, 144 | data.y, data.z, hrs_val, als_val); 145 | } 146 | 147 | void set_backlight(uint8_t light_level) 148 | { 149 | std::bitset<3> bits(light_level); 150 | 151 | backlight_high = bits[2]; 152 | backlight_mid = bits[1]; 153 | backlight_low = bits[0]; 154 | } 155 | 156 | void i2c_scan(mbed::I2C &i2c) 157 | { 158 | printf("I2C Scan...\r\n"); 159 | for (int i = 0; i < 128; i++) 160 | { 161 | i2c.start(); 162 | int ret = i2c.write(i << 1); 163 | if (ret == 1) 164 | { 165 | printf("0x%x ACK \r\n", i); // Send command string 166 | } 167 | else 168 | { 169 | printf("0x%x NO ACK, returned %i \r\n", i, ret); // Send command string 170 | } 171 | i2c.stop(); 172 | } 173 | printf("I2C Scan End \r\n"); 174 | } 175 | 176 | void on_touch_event(struct CST0xx_TouchPad::ts_event event) 177 | { 178 | display.setTextSize(2); 179 | display.setCursor(0, 200); 180 | display.setTextColor(0xF800, 0xFFFF); 181 | switch (event.type) 182 | { 183 | case CST0xx_TouchPad::EVENT_TYPE_TOUCH: 184 | display.printf("TOUCH X: %u Y: %u", event.x, event.y); 185 | tr_info("TOUCH X: %u Y: %u", event.x, event.y); 186 | break; 187 | case CST0xx_TouchPad::EVENT_TYPE_LONG_TOUCH: 188 | display.printf("TOUCH LONG X: %u Y: %u", event.x, event.y); 189 | tr_info("TOUCH LONG X: %u Y: %u", event.x, event.y); 190 | break; 191 | case CST0xx_TouchPad::EVENT_TYPE_SWIPE_Y_POSITIVE: 192 | display.printf("SWIPE y+ X: %u Y: %u", event.x, event.y); 193 | tr_info("SWIPE y+ X: %u Y: %u", event.x, event.y); 194 | break; 195 | case CST0xx_TouchPad::EVENT_TYPE_SWIPE_X_POSITIVE: 196 | display.printf("SWIPE x+ X: %u Y: %u", event.x, event.y); 197 | tr_info("SWIPE x+ X: %u Y: %u", event.x, event.y); 198 | break; 199 | case CST0xx_TouchPad::EVENT_TYPE_SWIPE_Y_NEGATIVE: 200 | display.printf("SWIPE y- X: %u Y: %u", event.x, event.y); 201 | tr_info("SWIPE y- X: %u Y: %u", event.x, event.y); 202 | break; 203 | case CST0xx_TouchPad::EVENT_TYPE_SWIPE_X_NEGATIVE: 204 | display.printf("SWIPE x- X: %u Y: %u", event.x, event.y); 205 | tr_info("SWIPE x- X: %u Y: %u", event.x, event.y); 206 | break; 207 | } 208 | 209 | display.fillRect(event.x - 5, event.y - 5, 10, 10, 0xF800); 210 | } 211 | 212 | void main_button_on_rise() { tr_info("Main Button Rise"); } 213 | 214 | void main_button_on_fall() { tr_info("Main Button Fall"); } 215 | -------------------------------------------------------------------------------- /apps/periph_test/source/ptime_accel.cpp: -------------------------------------------------------------------------------- 1 | #include "ptime_accel.h" 2 | 3 | #include "bma421.h" 4 | 5 | #include "drivers/I2C.h" 6 | #include "rtos/ThisThread.h" 7 | 8 | #include "mbed-trace/mbed_trace.h" 9 | #define TRACE_GROUP "PACL" 10 | 11 | uint16_t i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 12 | uint16_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 13 | void delay_ms(uint32_t period); 14 | 15 | mbed::I2C *i2c_instance; 16 | 17 | uint16_t ptime_accel_init(struct bma4_dev *dev, mbed::I2C *i2c) 18 | { 19 | i2c_instance = i2c; 20 | struct bma4_accel_config conf; 21 | int8_t rslt; 22 | 23 | /* Modify the parameters */ 24 | dev->dev_addr = BMA4_I2C_ADDR_PRIMARY; 25 | dev->interface = BMA4_I2C_INTERFACE; 26 | dev->bus_read = i2c_reg_read; 27 | dev->bus_write = i2c_reg_write; 28 | dev->delay = delay_ms; 29 | dev->read_write_len = 8; 30 | 31 | // From Init Function 32 | dev->variant = BMA42X_VARIANT; 33 | dev->resolution = 12; 34 | 35 | tr_info("Accel Init"); 36 | rslt = bma421_init(dev); 37 | ptime_accel_print_rslt(rslt); 38 | 39 | // tr_info("Write Feature Config Blob File"); 40 | // rslt = bma421_write_config_file(&bma); 41 | // print_rslt(rslt); 42 | 43 | tr_info("Accel Enable"); 44 | rslt = bma4_set_accel_enable(BMA4_ENABLE, dev); 45 | ptime_accel_print_rslt(rslt); 46 | 47 | conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ; 48 | conf.range = BMA4_ACCEL_RANGE_2G; 49 | conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4; 50 | conf.perf_mode = BMA4_CONTINUOUS_MODE; 51 | 52 | tr_info("Accel Set Config"); 53 | rslt = bma4_set_accel_config(&conf, dev); 54 | ptime_accel_print_rslt(rslt); 55 | 56 | return rslt; 57 | } 58 | 59 | void ptime_accel_print_rslt(uint16_t rslt) 60 | { 61 | switch (rslt) 62 | { 63 | case BMA4_OK: 64 | tr_info("Success."); 65 | break; 66 | case BMA4_E_NULL_PTR: 67 | tr_err("Error [%d] : Null pointer", rslt); 68 | break; 69 | case BMA4_E_OUT_OF_RANGE: 70 | tr_err("Error [%d] : Out of range", rslt); 71 | break; 72 | case BMA4_E_INVALID_SENSOR: 73 | tr_err("Error [%d] : Invalid sensor", rslt); 74 | break; 75 | case BMA4_E_CONFIG_STREAM_ERROR: 76 | tr_err("Error [%d] : Config stream error", rslt); 77 | break; 78 | case BMA4_E_SELF_TEST_FAIL: 79 | tr_err("Warning [%d] : Self test failed", rslt); 80 | break; 81 | default: 82 | tr_err("Error [%d] : Unknown error code", rslt); 83 | break; 84 | } 85 | } 86 | 87 | uint16_t i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) 88 | { 89 | 90 | /* Write to registers using I2C. Return 0 for a successful execution. */ 91 | int ret = 0; 92 | const int TEMP_BUF_SIZE = 32; 93 | if (length > TEMP_BUF_SIZE) 94 | { 95 | return -2; 96 | } 97 | uint8_t tmp[TEMP_BUF_SIZE]; 98 | tmp[0] = reg_addr; 99 | memcpy(tmp + 1, reg_data, length); 100 | 101 | ret = i2c_instance->write(i2c_addr << 1, (const char *)tmp, length + 1, false); 102 | 103 | if (!ret) 104 | { 105 | return 0; 106 | } 107 | tr_err("I2C Write Failed, returned %i", ret); 108 | return -1; 109 | } 110 | 111 | uint16_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length) 112 | { 113 | 114 | /* Read from registers using I2C. Return 0 for a successful execution. */ 115 | 116 | int ret = 0; 117 | 118 | ret = i2c_instance->write(i2c_addr << 1, (const char *)®_addr, 1, true); 119 | if (!ret) 120 | { 121 | ret = i2c_instance->read(i2c_addr << 1, (char *)reg_data, length, false); 122 | } 123 | else 124 | { 125 | tr_err("I2C Read Failed writting address, returned %i.", ret); 126 | } 127 | 128 | if (!ret) 129 | { 130 | return 0; 131 | } 132 | tr_err("I2C Read Failed, returned %i.", ret); 133 | return -1; 134 | } 135 | 136 | void delay_ms(uint32_t period) { rtos::ThisThread::sleep_for(period); } -------------------------------------------------------------------------------- /apps/periph_test/source/ptime_accel.h: -------------------------------------------------------------------------------- 1 | #include "bma421.h" 2 | 3 | #include "drivers/I2C.h" 4 | 5 | uint16_t ptime_accel_init(struct bma4_dev *dev, mbed::I2C *i2c); 6 | void ptime_accel_print_rslt(uint16_t rslt); 7 | -------------------------------------------------------------------------------- /drivers/Adafruit_GFX/Adafruit_GFX.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is the core graphics library for all our displays, providing a common 3 | set of graphics primitives (points, lines, circles, etc.). It needs to be 4 | paired with a hardware-specific library for each display device we carry 5 | (to handle the lower-level functions). 6 | 7 | Adafruit invests time and resources providing this open source code, please 8 | support Adafruit & open-source hardware by purchasing products from Adafruit! 9 | 10 | Copyright (c) 2013 Adafruit Industries. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "mbed.h" 35 | #include "Adafruit_GFX.h" 36 | #include "glcdfont.h" 37 | 38 | Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h): WIDTH(w), HEIGHT(h) { 39 | 40 | _width = WIDTH; 41 | _height = HEIGHT; 42 | 43 | rotation = 0; 44 | cursor_y = cursor_x = 0; 45 | textsize = 1; 46 | textcolor = textbgcolor = 0xFFFF; 47 | wrap = true; 48 | } 49 | 50 | 51 | // draw a circle outline 52 | void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, 53 | uint16_t color) { 54 | int16_t f = 1 - r; 55 | int16_t ddF_x = 1; 56 | int16_t ddF_y = -2 * r; 57 | int16_t x = 0; 58 | int16_t y = r; 59 | 60 | drawPixel(x0, y0+r, color); 61 | drawPixel(x0, y0-r, color); 62 | drawPixel(x0+r, y0, color); 63 | drawPixel(x0-r, y0, color); 64 | 65 | while (x= 0) { 67 | y--; 68 | ddF_y += 2; 69 | f += ddF_y; 70 | } 71 | x++; 72 | ddF_x += 2; 73 | f += ddF_x; 74 | 75 | drawPixel(x0 + x, y0 + y, color); 76 | drawPixel(x0 - x, y0 + y, color); 77 | drawPixel(x0 + x, y0 - y, color); 78 | drawPixel(x0 - x, y0 - y, color); 79 | drawPixel(x0 + y, y0 + x, color); 80 | drawPixel(x0 - y, y0 + x, color); 81 | drawPixel(x0 + y, y0 - x, color); 82 | drawPixel(x0 - y, y0 - x, color); 83 | 84 | } 85 | } 86 | 87 | void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, 88 | int16_t r, uint8_t cornername, uint16_t color) { 89 | int16_t f = 1 - r; 90 | int16_t ddF_x = 1; 91 | int16_t ddF_y = -2 * r; 92 | int16_t x = 0; 93 | int16_t y = r; 94 | 95 | while (x= 0) { 97 | y--; 98 | ddF_y += 2; 99 | f += ddF_y; 100 | } 101 | x++; 102 | ddF_x += 2; 103 | f += ddF_x; 104 | if (cornername & 0x4) { 105 | drawPixel(x0 + x, y0 + y, color); 106 | drawPixel(x0 + y, y0 + x, color); 107 | } 108 | if (cornername & 0x2) { 109 | drawPixel(x0 + x, y0 - y, color); 110 | drawPixel(x0 + y, y0 - x, color); 111 | } 112 | if (cornername & 0x8) { 113 | drawPixel(x0 - y, y0 + x, color); 114 | drawPixel(x0 - x, y0 + y, color); 115 | } 116 | if (cornername & 0x1) { 117 | drawPixel(x0 - y, y0 - x, color); 118 | drawPixel(x0 - x, y0 - y, color); 119 | } 120 | } 121 | } 122 | 123 | void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, 124 | uint16_t color) { 125 | drawFastVLine(x0, y0-r, 2*r+1, color); 126 | fillCircleHelper(x0, y0, r, 3, 0, color); 127 | } 128 | 129 | // used to do circles and roundrects! 130 | void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 131 | uint8_t cornername, int16_t delta, uint16_t color) { 132 | 133 | int16_t f = 1 - r; 134 | int16_t ddF_x = 1; 135 | int16_t ddF_y = -2 * r; 136 | int16_t x = 0; 137 | int16_t y = r; 138 | 139 | while (x= 0) { 141 | y--; 142 | ddF_y += 2; 143 | f += ddF_y; 144 | } 145 | x++; 146 | ddF_x += 2; 147 | f += ddF_x; 148 | 149 | if (cornername & 0x1) { 150 | drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); 151 | drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); 152 | } 153 | if (cornername & 0x2) { 154 | drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); 155 | drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); 156 | } 157 | } 158 | } 159 | 160 | // bresenham's algorithm - thx wikpedia 161 | void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, 162 | int16_t x1, int16_t y1, 163 | uint16_t color) { 164 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); 165 | if (steep) { 166 | aswap(x0, y0); 167 | aswap(x1, y1); 168 | } 169 | 170 | if (x0 > x1) { 171 | aswap(x0, x1); 172 | aswap(y0, y1); 173 | } 174 | 175 | int16_t dx, dy; 176 | dx = x1 - x0; 177 | dy = abs(y1 - y0); 178 | 179 | int16_t err = dx / 2; 180 | int16_t ystep; 181 | 182 | if (y0 < y1) { 183 | ystep = 1; 184 | } else { 185 | ystep = -1; 186 | } 187 | 188 | for (; x0<=x1; x0++) { 189 | if (steep) { 190 | drawPixel(y0, x0, color); 191 | } else { 192 | drawPixel(x0, y0, color); 193 | } 194 | err -= dy; 195 | if (err < 0) { 196 | y0 += ystep; 197 | err += dx; 198 | } 199 | } 200 | } 201 | 202 | 203 | // draw a rectangle 204 | void Adafruit_GFX::drawRect(int16_t x, int16_t y, 205 | int16_t w, int16_t h, 206 | uint16_t color) { 207 | drawFastHLine(x, y, w, color); 208 | drawFastHLine(x, y+h-1, w, color); 209 | drawFastVLine(x, y, h, color); 210 | drawFastVLine(x+w-1, y, h, color); 211 | } 212 | 213 | void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, 214 | int16_t h, uint16_t color) { 215 | // stupidest version - update in subclasses if desired! 216 | drawLine(x, y, x, y+h-1, color); 217 | } 218 | 219 | 220 | void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, 221 | int16_t w, uint16_t color) { 222 | // stupidest version - update in subclasses if desired! 223 | drawLine(x, y, x+w-1, y, color); 224 | } 225 | 226 | void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 227 | uint16_t color) { 228 | // stupidest version - update in subclasses if desired! 229 | for (int16_t i=x; i= y1 >= y0) 282 | if (y0 > y1) { 283 | aswap(y0, y1); aswap(x0, x1); 284 | } 285 | if (y1 > y2) { 286 | aswap(y2, y1); aswap(x2, x1); 287 | } 288 | if (y0 > y1) { 289 | aswap(y0, y1); aswap(x0, x1); 290 | } 291 | 292 | if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing 293 | a = b = x0; 294 | if(x1 < a) a = x1; 295 | else if(x1 > b) b = x1; 296 | if(x2 < a) a = x2; 297 | else if(x2 > b) b = x2; 298 | drawFastHLine(a, y0, b-a+1, color); 299 | return; 300 | } 301 | 302 | int16_t 303 | dx01 = x1 - x0, 304 | dy01 = y1 - y0, 305 | dx02 = x2 - x0, 306 | dy02 = y2 - y0, 307 | dx12 = x2 - x1, 308 | dy12 = y2 - y1, 309 | sa = 0, 310 | sb = 0; 311 | 312 | // For upper part of triangle, find scanline crossings for segments 313 | // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 314 | // is included here (and second loop will be skipped, avoiding a /0 315 | // error there), otherwise scanline y1 is skipped here and handled 316 | // in the second loop...which also avoids a /0 error here if y0=y1 317 | // (flat-topped triangle). 318 | if(y1 == y2) last = y1; // Include y1 scanline 319 | else last = y1-1; // Skip it 320 | 321 | for(y=y0; y<=last; y++) { 322 | a = x0 + sa / dy01; 323 | b = x0 + sb / dy02; 324 | sa += dx01; 325 | sb += dx02; 326 | /* longhand: 327 | a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); 328 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 329 | */ 330 | if(a > b) aswap(a,b); 331 | drawFastHLine(a, y, b-a+1, color); 332 | } 333 | 334 | // For lower part of triangle, find scanline crossings for segments 335 | // 0-2 and 1-2. This loop is skipped if y1=y2. 336 | sa = dx12 * (y - y1); 337 | sb = dx02 * (y - y0); 338 | for(; y<=y2; y++) { 339 | a = x1 + sa / dy12; 340 | b = x0 + sb / dy02; 341 | sa += dx12; 342 | sb += dx02; 343 | /* longhand: 344 | a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); 345 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 346 | */ 347 | if(a > b) aswap(a,b); 348 | drawFastHLine(a, y, b-a+1, color); 349 | } 350 | } 351 | 352 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 353 | const uint8_t *bitmap, int16_t w, int16_t h, 354 | uint16_t color) { 355 | 356 | int16_t i, j, byteWidth = (w + 7) / 8; 357 | 358 | for(j=0; j> (i & 7))) { 361 | if(bitmap[ j * byteWidth + i / 8] & (128 >> (i & 7))) { 362 | drawPixel(x+i, y+j, color); 363 | } 364 | } 365 | } 366 | } 367 | 368 | int Adafruit_GFX::_putc(int c) { 369 | if (c == '\n') { 370 | cursor_y += textsize*8; 371 | cursor_x = 0; 372 | } else if (c == '\r') { 373 | // skip em 374 | } else { 375 | drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 376 | cursor_x += textsize*6; 377 | if (wrap && (cursor_x > (_width - textsize*6))) { 378 | cursor_y += textsize*8; 379 | cursor_x = 0; 380 | } 381 | } 382 | 383 | return c; 384 | } 385 | int Adafruit_GFX::_getc() { 386 | return -1; 387 | } 388 | 389 | // draw a character 390 | void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, 391 | uint16_t color, uint16_t bg, uint8_t size) { 392 | 393 | if((x >= _width) || // Clip right 394 | (y >= _height) || // Clip bottom 395 | ((x + 6 * size - 1) < 0) || // Clip left 396 | ((y + 8 * size - 1) < 0)) // Clip top 397 | return; 398 | 399 | for (int8_t i=0; i<6; i++ ) { 400 | uint8_t line; 401 | if (i == 5) 402 | line = 0x0; 403 | else 404 | line = font[(c*5)+i]; 405 | for (int8_t j = 0; j<8; j++) { 406 | if (line & 0x1) { 407 | if (size == 1) // default size 408 | drawPixel(x+i, y+j, color); 409 | else { // big size 410 | fillRect(x+(i*size), y+(j*size), size, size, color); 411 | } 412 | } else if (bg != color) { 413 | if (size == 1) // default size 414 | drawPixel(x+i, y+j, bg); 415 | else { // big size 416 | fillRect(x+i*size, y+j*size, size, size, bg); 417 | } 418 | } 419 | line >>= 1; 420 | } 421 | } 422 | } 423 | 424 | void Adafruit_GFX::setCursor(int16_t x, int16_t y) { 425 | cursor_x = x; 426 | cursor_y = y; 427 | } 428 | 429 | 430 | void Adafruit_GFX::setTextSize(uint8_t s) { 431 | textsize = (s > 0) ? s : 1; 432 | } 433 | 434 | 435 | void Adafruit_GFX::setTextColor(uint16_t c) { 436 | textcolor = c; 437 | textbgcolor = c; 438 | // for 'transparent' background, we'll set the bg 439 | // to the same as fg instead of using a flag 440 | } 441 | 442 | void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) { 443 | textcolor = c; 444 | textbgcolor = b; 445 | } 446 | 447 | void Adafruit_GFX::setTextWrap(boolean w) { 448 | wrap = w; 449 | } 450 | 451 | uint8_t Adafruit_GFX::getRotation(void) { 452 | rotation %= 4; 453 | return rotation; 454 | } 455 | 456 | void Adafruit_GFX::setRotation(uint8_t x) { 457 | x %= 4; // cant be higher than 3 458 | rotation = x; 459 | switch (x) { 460 | case 0: 461 | case 2: 462 | _width = WIDTH; 463 | _height = HEIGHT; 464 | break; 465 | case 1: 466 | case 3: 467 | _width = HEIGHT; 468 | _height = WIDTH; 469 | break; 470 | } 471 | } 472 | 473 | 474 | void Adafruit_GFX::invertDisplay(boolean i) { 475 | // do nothing, can be subclassed 476 | } 477 | 478 | 479 | // return the size of the display which depends on the rotation! 480 | int16_t Adafruit_GFX::width(void) { 481 | return _width; 482 | } 483 | 484 | int16_t Adafruit_GFX::height(void) { 485 | return _height; 486 | } 487 | -------------------------------------------------------------------------------- /drivers/Adafruit_GFX/Adafruit_GFX.h: -------------------------------------------------------------------------------- 1 | /* 2 | This is the core graphics library for all our displays, providing a common 3 | set of graphics primitives (points, lines, circles, etc.). It needs to be 4 | paired with a hardware-specific library for each display device we carry 5 | (to handle the lower-level functions). 6 | 7 | Adafruit invests time and resources providing this open source code, please 8 | support Adafruit & open-source hardware by purchasing products from Adafruit! 9 | 10 | Copyright (c) 2013 Adafruit Industries. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _ADAFRUIT_GFX_H 35 | #define _ADAFRUIT_GFX_H 36 | 37 | #include "mbed.h" 38 | #include "Stream.h" 39 | 40 | 41 | #define aswap(a, b) { int16_t t = a; a = b; b = t; } 42 | #define boolean bool 43 | 44 | class Adafruit_GFX : public Stream 45 | { 46 | public: 47 | 48 | //Adafruit_GFX(); 49 | Adafruit_GFX(int16_t w, int16_t h); // Constructor 50 | // i have no idea why we have to formally call the constructor. kinda sux 51 | //void constructor(int16_t w, int16_t h); 52 | 53 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 54 | virtual void invertDisplay(boolean i); 55 | 56 | // these are 'generic' drawing functions, so we can share them! 57 | void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,uint16_t color); 58 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 59 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 60 | virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 61 | virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 62 | virtual void fillScreen(uint16_t color); 63 | 64 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 65 | void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); 66 | void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 67 | void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); 68 | 69 | void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,int16_t x2, int16_t y2, uint16_t color); 70 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 71 | void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); 72 | void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); 73 | 74 | void drawBitmap(int16_t x, int16_t y, 75 | const uint8_t *bitmap, int16_t w, int16_t h, 76 | uint16_t color); 77 | void drawChar(int16_t x, int16_t y, unsigned char c, 78 | uint16_t color, uint16_t bg, uint8_t size); 79 | 80 | void setCursor(int16_t x, int16_t y); 81 | void setTextColor(uint16_t c); 82 | void setTextColor(uint16_t c, uint16_t bg); 83 | void setTextSize(uint8_t s); 84 | void setTextWrap(boolean w); 85 | 86 | int16_t height(void); 87 | int16_t width(void); 88 | 89 | void setRotation(uint8_t r); 90 | uint8_t getRotation(void); 91 | 92 | protected: 93 | virtual int _putc(int value); 94 | virtual int _getc(); 95 | 96 | const int16_t WIDTH, HEIGHT; // this is the 'raw' display w/h - never changes 97 | int16_t _width, _height; // dependent on rotation 98 | int16_t cursor_x, cursor_y; 99 | uint16_t textcolor, textbgcolor; 100 | uint8_t textsize; 101 | uint8_t rotation; 102 | boolean wrap; // If set, 'wrap' text at right edge of display 103 | }; 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /drivers/Adafruit_GFX/README.md: -------------------------------------------------------------------------------- 1 | Vendored from https://os.mbed.com/users/SomeRandomBloke/code/Adafruit_GFX/ at revision 3:83bcb23eed69 -------------------------------------------------------------------------------- /drivers/Adafruit_GFX/glcdfont.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FONT5X7_H 3 | #define FONT5X7_H 4 | 5 | // standard ascii 5x7 font 6 | 7 | unsigned char font[] = { 8 | 0x00, 0x00, 0x00, 0x00, 0x00, 9 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 10 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 11 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 12 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 13 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 14 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 15 | 0x00, 0x18, 0x3C, 0x18, 0x00, 16 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 17 | 0x00, 0x18, 0x24, 0x18, 0x00, 18 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 19 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 20 | 0x26, 0x29, 0x79, 0x29, 0x26, 21 | 0x40, 0x7F, 0x05, 0x05, 0x07, 22 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 23 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 24 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 25 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 26 | 0x14, 0x22, 0x7F, 0x22, 0x14, 27 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 28 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 29 | 0x00, 0x66, 0x89, 0x95, 0x6A, 30 | 0x60, 0x60, 0x60, 0x60, 0x60, 31 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 32 | 0x08, 0x04, 0x7E, 0x04, 0x08, 33 | 0x10, 0x20, 0x7E, 0x20, 0x10, 34 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 35 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 36 | 0x1E, 0x10, 0x10, 0x10, 0x10, 37 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 38 | 0x30, 0x38, 0x3E, 0x38, 0x30, 39 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x5F, 0x00, 0x00, 42 | 0x00, 0x07, 0x00, 0x07, 0x00, 43 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 44 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 45 | 0x23, 0x13, 0x08, 0x64, 0x62, 46 | 0x36, 0x49, 0x56, 0x20, 0x50, 47 | 0x00, 0x08, 0x07, 0x03, 0x00, 48 | 0x00, 0x1C, 0x22, 0x41, 0x00, 49 | 0x00, 0x41, 0x22, 0x1C, 0x00, 50 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 51 | 0x08, 0x08, 0x3E, 0x08, 0x08, 52 | 0x00, 0x80, 0x70, 0x30, 0x00, 53 | 0x08, 0x08, 0x08, 0x08, 0x08, 54 | 0x00, 0x00, 0x60, 0x60, 0x00, 55 | 0x20, 0x10, 0x08, 0x04, 0x02, 56 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 57 | 0x00, 0x42, 0x7F, 0x40, 0x00, 58 | 0x72, 0x49, 0x49, 0x49, 0x46, 59 | 0x21, 0x41, 0x49, 0x4D, 0x33, 60 | 0x18, 0x14, 0x12, 0x7F, 0x10, 61 | 0x27, 0x45, 0x45, 0x45, 0x39, 62 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 63 | 0x41, 0x21, 0x11, 0x09, 0x07, 64 | 0x36, 0x49, 0x49, 0x49, 0x36, 65 | 0x46, 0x49, 0x49, 0x29, 0x1E, 66 | 0x00, 0x00, 0x14, 0x00, 0x00, 67 | 0x00, 0x40, 0x34, 0x00, 0x00, 68 | 0x00, 0x08, 0x14, 0x22, 0x41, 69 | 0x14, 0x14, 0x14, 0x14, 0x14, 70 | 0x00, 0x41, 0x22, 0x14, 0x08, 71 | 0x02, 0x01, 0x59, 0x09, 0x06, 72 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 73 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 74 | 0x7F, 0x49, 0x49, 0x49, 0x36, 75 | 0x3E, 0x41, 0x41, 0x41, 0x22, 76 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 77 | 0x7F, 0x49, 0x49, 0x49, 0x41, 78 | 0x7F, 0x09, 0x09, 0x09, 0x01, 79 | 0x3E, 0x41, 0x41, 0x51, 0x73, 80 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 81 | 0x00, 0x41, 0x7F, 0x41, 0x00, 82 | 0x20, 0x40, 0x41, 0x3F, 0x01, 83 | 0x7F, 0x08, 0x14, 0x22, 0x41, 84 | 0x7F, 0x40, 0x40, 0x40, 0x40, 85 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 86 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 87 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 88 | 0x7F, 0x09, 0x09, 0x09, 0x06, 89 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 90 | 0x7F, 0x09, 0x19, 0x29, 0x46, 91 | 0x26, 0x49, 0x49, 0x49, 0x32, 92 | 0x03, 0x01, 0x7F, 0x01, 0x03, 93 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 94 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 95 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 96 | 0x63, 0x14, 0x08, 0x14, 0x63, 97 | 0x03, 0x04, 0x78, 0x04, 0x03, 98 | 0x61, 0x59, 0x49, 0x4D, 0x43, 99 | 0x00, 0x7F, 0x41, 0x41, 0x41, 100 | 0x02, 0x04, 0x08, 0x10, 0x20, 101 | 0x00, 0x41, 0x41, 0x41, 0x7F, 102 | 0x04, 0x02, 0x01, 0x02, 0x04, 103 | 0x40, 0x40, 0x40, 0x40, 0x40, 104 | 0x00, 0x03, 0x07, 0x08, 0x00, 105 | 0x20, 0x54, 0x54, 0x78, 0x40, 106 | 0x7F, 0x28, 0x44, 0x44, 0x38, 107 | 0x38, 0x44, 0x44, 0x44, 0x28, 108 | 0x38, 0x44, 0x44, 0x28, 0x7F, 109 | 0x38, 0x54, 0x54, 0x54, 0x18, 110 | 0x00, 0x08, 0x7E, 0x09, 0x02, 111 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 112 | 0x7F, 0x08, 0x04, 0x04, 0x78, 113 | 0x00, 0x44, 0x7D, 0x40, 0x00, 114 | 0x20, 0x40, 0x40, 0x3D, 0x00, 115 | 0x7F, 0x10, 0x28, 0x44, 0x00, 116 | 0x00, 0x41, 0x7F, 0x40, 0x00, 117 | 0x7C, 0x04, 0x78, 0x04, 0x78, 118 | 0x7C, 0x08, 0x04, 0x04, 0x78, 119 | 0x38, 0x44, 0x44, 0x44, 0x38, 120 | 0xFC, 0x18, 0x24, 0x24, 0x18, 121 | 0x18, 0x24, 0x24, 0x18, 0xFC, 122 | 0x7C, 0x08, 0x04, 0x04, 0x08, 123 | 0x48, 0x54, 0x54, 0x54, 0x24, 124 | 0x04, 0x04, 0x3F, 0x44, 0x24, 125 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 126 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 127 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 128 | 0x44, 0x28, 0x10, 0x28, 0x44, 129 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 130 | 0x44, 0x64, 0x54, 0x4C, 0x44, 131 | 0x00, 0x08, 0x36, 0x41, 0x00, 132 | 0x00, 0x00, 0x77, 0x00, 0x00, 133 | 0x00, 0x41, 0x36, 0x08, 0x00, 134 | 0x02, 0x01, 0x02, 0x04, 0x02, 135 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 136 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 137 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 138 | 0x38, 0x54, 0x54, 0x55, 0x59, 139 | 0x21, 0x55, 0x55, 0x79, 0x41, 140 | 0x21, 0x54, 0x54, 0x78, 0x41, 141 | 0x21, 0x55, 0x54, 0x78, 0x40, 142 | 0x20, 0x54, 0x55, 0x79, 0x40, 143 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 144 | 0x39, 0x55, 0x55, 0x55, 0x59, 145 | 0x39, 0x54, 0x54, 0x54, 0x59, 146 | 0x39, 0x55, 0x54, 0x54, 0x58, 147 | 0x00, 0x00, 0x45, 0x7C, 0x41, 148 | 0x00, 0x02, 0x45, 0x7D, 0x42, 149 | 0x00, 0x01, 0x45, 0x7C, 0x40, 150 | 0xF0, 0x29, 0x24, 0x29, 0xF0, 151 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 152 | 0x7C, 0x54, 0x55, 0x45, 0x00, 153 | 0x20, 0x54, 0x54, 0x7C, 0x54, 154 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 155 | 0x32, 0x49, 0x49, 0x49, 0x32, 156 | 0x32, 0x48, 0x48, 0x48, 0x32, 157 | 0x32, 0x4A, 0x48, 0x48, 0x30, 158 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 159 | 0x3A, 0x42, 0x40, 0x20, 0x78, 160 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 161 | 0x39, 0x44, 0x44, 0x44, 0x39, 162 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 163 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 164 | 0x48, 0x7E, 0x49, 0x43, 0x66, 165 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 166 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 167 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 168 | 0x20, 0x54, 0x54, 0x79, 0x41, 169 | 0x00, 0x00, 0x44, 0x7D, 0x41, 170 | 0x30, 0x48, 0x48, 0x4A, 0x32, 171 | 0x38, 0x40, 0x40, 0x22, 0x7A, 172 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 173 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 174 | 0x26, 0x29, 0x29, 0x2F, 0x28, 175 | 0x26, 0x29, 0x29, 0x29, 0x26, 176 | 0x30, 0x48, 0x4D, 0x40, 0x20, 177 | 0x38, 0x08, 0x08, 0x08, 0x08, 178 | 0x08, 0x08, 0x08, 0x08, 0x38, 179 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 180 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 181 | 0x00, 0x00, 0x7B, 0x00, 0x00, 182 | 0x08, 0x14, 0x2A, 0x14, 0x22, 183 | 0x22, 0x14, 0x2A, 0x14, 0x08, 184 | 0xAA, 0x00, 0x55, 0x00, 0xAA, 185 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 186 | 0x00, 0x00, 0x00, 0xFF, 0x00, 187 | 0x10, 0x10, 0x10, 0xFF, 0x00, 188 | 0x14, 0x14, 0x14, 0xFF, 0x00, 189 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 190 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 191 | 0x14, 0x14, 0x14, 0xFC, 0x00, 192 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 193 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 194 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 195 | 0x14, 0x14, 0x17, 0x10, 0x1F, 196 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 197 | 0x14, 0x14, 0x14, 0x1F, 0x00, 198 | 0x10, 0x10, 0x10, 0xF0, 0x00, 199 | 0x00, 0x00, 0x00, 0x1F, 0x10, 200 | 0x10, 0x10, 0x10, 0x1F, 0x10, 201 | 0x10, 0x10, 0x10, 0xF0, 0x10, 202 | 0x00, 0x00, 0x00, 0xFF, 0x10, 203 | 0x10, 0x10, 0x10, 0x10, 0x10, 204 | 0x10, 0x10, 0x10, 0xFF, 0x10, 205 | 0x00, 0x00, 0x00, 0xFF, 0x14, 206 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 207 | 0x00, 0x00, 0x1F, 0x10, 0x17, 208 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 209 | 0x14, 0x14, 0x17, 0x10, 0x17, 210 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 211 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 212 | 0x14, 0x14, 0x14, 0x14, 0x14, 213 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 214 | 0x14, 0x14, 0x14, 0x17, 0x14, 215 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 216 | 0x14, 0x14, 0x14, 0xF4, 0x14, 217 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 218 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 219 | 0x00, 0x00, 0x00, 0x1F, 0x14, 220 | 0x00, 0x00, 0x00, 0xFC, 0x14, 221 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 222 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 223 | 0x14, 0x14, 0x14, 0xFF, 0x14, 224 | 0x10, 0x10, 0x10, 0x1F, 0x00, 225 | 0x00, 0x00, 0x00, 0xF0, 0x10, 226 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 227 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 228 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 229 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 230 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 231 | 0x38, 0x44, 0x44, 0x38, 0x44, 232 | 0x7C, 0x2A, 0x2A, 0x3E, 0x14, 233 | 0x7E, 0x02, 0x02, 0x06, 0x06, 234 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 235 | 0x63, 0x55, 0x49, 0x41, 0x63, 236 | 0x38, 0x44, 0x44, 0x3C, 0x04, 237 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 238 | 0x06, 0x02, 0x7E, 0x02, 0x02, 239 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 240 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 241 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 242 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 243 | 0x30, 0x48, 0x78, 0x48, 0x30, 244 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 245 | 0x3E, 0x49, 0x49, 0x49, 0x00, 246 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 247 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 248 | 0x44, 0x44, 0x5F, 0x44, 0x44, 249 | 0x40, 0x51, 0x4A, 0x44, 0x40, 250 | 0x40, 0x44, 0x4A, 0x51, 0x40, 251 | 0x00, 0x00, 0xFF, 0x01, 0x03, 252 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 253 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 254 | 0x36, 0x12, 0x36, 0x24, 0x36, 255 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 256 | 0x00, 0x00, 0x18, 0x18, 0x00, 257 | 0x00, 0x00, 0x10, 0x10, 0x00, 258 | 0x30, 0x40, 0xFF, 0x01, 0x01, 259 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 260 | 0x00, 0x19, 0x1D, 0x17, 0x12, 261 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 262 | 0x00, 0x00, 0x00, 0x00, 0x00, 263 | }; 264 | #endif 265 | -------------------------------------------------------------------------------- /drivers/Adafruit_ST7789/Adafruit_ST7789.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library is a modification of the Mbed Adafruit_ST7735 library 3 | for 1.3" IPS displays commonly available, which are 240x240 and run 4 | on the ST7789. 5 | 6 | Check out the links above for our tutorials and wiring diagrams 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface (RST is optional) 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Modified by Sreeteja Jonnada. 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #include "mbed.h" 19 | #include "Adafruit_ST7789.h" 20 | 21 | inline uint16_t swapcolor(uint16_t x) { 22 | return (x << 11) | (x & 0x07E0) | (x >> 11); 23 | } 24 | 25 | // Constructor 26 | Adafruit_ST7789::Adafruit_ST7789(PinName mosi, PinName miso, PinName sck, PinName cs, PinName rs, PinName rst) 27 | : lcdPort(mosi, miso, sck), _cs(cs), _rs(rs), _rst(rst), Adafruit_GFX(WIDTH, HEIGHT) 28 | { } 29 | 30 | 31 | void Adafruit_ST7789::writecommand(uint8_t c) 32 | { 33 | _rs = 0; 34 | _cs = 0; 35 | lcdPort.write( c ); 36 | _cs = 1; 37 | } 38 | 39 | 40 | void Adafruit_ST7789::writedata(uint8_t c) 41 | { 42 | _rs = 1; 43 | _cs = 0; 44 | lcdPort.write( c ); 45 | 46 | _cs = 1; 47 | } 48 | 49 | 50 | // Initialization for ST7789 screens 51 | void Adafruit_ST7789::init(void) 52 | { 53 | lcdPort.format(8,3); 54 | lcdPort.frequency(8000000); 55 | 56 | _rst = 0; 57 | wait_ms(50); 58 | _rst = 1; 59 | wait_ms(100); 60 | 61 | writecommand(ST7789_SWRESET); 62 | wait_ms(150); 63 | writecommand(ST7789_SLPOUT); 64 | wait_ms(500); 65 | writecommand(ST7789_COLMOD); 66 | writedata(0x55); 67 | wait_ms(10); 68 | writecommand(ST7789_MADCTL); 69 | writedata(0x00); 70 | writecommand(ST7789_CASET); 71 | writedata(0x00); 72 | writedata(0); 73 | writedata(HEIGHT >> 8); 74 | writedata(HEIGHT & 0xFF); 75 | writecommand(ST7789_RASET); 76 | writedata(0x00); 77 | writedata(0); 78 | writedata(WIDTH >> 8); 79 | writedata(WIDTH & 0xFF); 80 | writecommand(ST7789_INVON); 81 | wait_ms(10); 82 | writecommand(ST7789_NORON); 83 | wait_ms(10); 84 | writecommand(ST7789_DISPON); 85 | wait_ms(500); 86 | 87 | writecommand(ST7789_DISPOFF); 88 | wait_ms(500); 89 | writecommand(ST7789_DISPON); 90 | wait_ms(500); 91 | writecommand(ST7789_DISPOFF); 92 | wait_ms(500); 93 | writecommand(ST7789_DISPON); 94 | wait_ms(500); 95 | writecommand(ST7789_DISPOFF); 96 | wait_ms(500); 97 | writecommand(ST7789_DISPON); 98 | wait_ms(500); 99 | } 100 | 101 | void Adafruit_ST7789::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, 102 | uint8_t y1) 103 | { 104 | 105 | writecommand(ST7789_CASET); // Column addr set 106 | writedata(0x00); 107 | writedata(x0); // XSTART 108 | writedata(0x00); 109 | writedata(x1); // XEND 110 | 111 | writecommand(ST7789_RASET); // Row addr set 112 | writedata(0x00); 113 | writedata(y0); // YSTART 114 | writedata(0x00); 115 | writedata(y1); // YEND 116 | 117 | writecommand(ST7789_RAMWR); // write to RAM 118 | } 119 | 120 | 121 | void Adafruit_ST7789::pushColor(uint16_t color) 122 | { 123 | _rs = 1; 124 | _cs = 0; 125 | 126 | lcdPort.write( color >> 8 ); 127 | lcdPort.write( color ); 128 | _cs = 1; 129 | } 130 | 131 | 132 | void Adafruit_ST7789::drawPixel(int16_t x, int16_t y, uint16_t color) 133 | { 134 | 135 | if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; 136 | 137 | setAddrWindow(x, y, x+1, y+1); 138 | _rs = 1; 139 | _cs = 0; 140 | lcdPort.write(color >> 8); 141 | lcdPort.write(color & 0xFF); 142 | } 143 | 144 | 145 | void Adafruit_ST7789::drawFastVLine(int16_t x, int16_t y, int16_t h, 146 | uint16_t color) 147 | { 148 | 149 | // Rudimentary clipping 150 | if((x >= _width) || (y >= _height)) return; 151 | if((y+h-1) >= _height) h = _height-y; 152 | setAddrWindow(x, y, x, y+h-1); 153 | 154 | uint8_t hi = color >> 8, lo = color; 155 | _rs = 1; 156 | _cs = 0; 157 | while (h--) { 158 | lcdPort.write( hi ); 159 | lcdPort.write( lo ); 160 | } 161 | _cs = 1; 162 | } 163 | 164 | 165 | void Adafruit_ST7789::drawFastHLine(int16_t x, int16_t y, int16_t w, 166 | uint16_t color) 167 | { 168 | 169 | // Rudimentary clipping 170 | if((x >= _width) || (y >= _height)) return; 171 | if((x+w-1) >= _width) w = _width-x; 172 | setAddrWindow(x, y, x+w-1, y); 173 | 174 | uint8_t hi = color >> 8, lo = color; 175 | _rs = 1; 176 | _cs = 0; 177 | while (w--) { 178 | lcdPort.write( hi ); 179 | lcdPort.write( lo ); 180 | } 181 | _cs = 1; 182 | } 183 | 184 | 185 | 186 | void Adafruit_ST7789::fillScreen(uint16_t color) 187 | { 188 | fillRect(0, 0, _width, _height, color); 189 | } 190 | 191 | 192 | // fill a rectangle 193 | void Adafruit_ST7789::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 194 | uint16_t color) 195 | { 196 | 197 | // rudimentary clipping (drawChar w/big text requires this) 198 | if((x >= _width) || (y >= _height)) return; 199 | if((x + w - 1) >= _width) w = _width - x; 200 | if((y + h - 1) >= _height) h = _height - y; 201 | 202 | setAddrWindow(x, y, x+w-1, y+h-1); 203 | 204 | uint8_t hi = color >> 8, lo = color; 205 | _rs = 1; 206 | _cs = 0; 207 | for(y=h; y>0; y--) { 208 | for(x=w; x>0; x--) { 209 | lcdPort.write( hi ); 210 | lcdPort.write( lo ); 211 | } 212 | } 213 | 214 | _cs = 1; 215 | } 216 | 217 | 218 | // Pass 8-bit (each) R,G,B, get back 16-bit packed color 219 | uint16_t Adafruit_ST7789::Color565(uint8_t r, uint8_t g, uint8_t b) 220 | { 221 | return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); 222 | } 223 | 224 | 225 | 226 | void Adafruit_ST7789::setRotation(uint8_t m) { 227 | 228 | // writecommand(ST7789_MADCTL); 229 | // rotation = m % 4; // can't be higher than 3 230 | } 231 | 232 | 233 | void Adafruit_ST7789::invertDisplay(boolean i) 234 | { 235 | writecommand(i ? ST7789_INVON : ST7789_INVOFF); 236 | } 237 | 238 | 239 | -------------------------------------------------------------------------------- /drivers/Adafruit_ST7789/Adafruit_ST7789.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library is a modification of the Mbed Adafruit_ST7735 library 3 | for 1.3" IPS displays commonly available, which are 240x240 and run 4 | on the ST7789. 5 | 6 | Check out the links above for our tutorials and wiring diagrams 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface (RST is optional) 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Modified by Sreeteja Jonnada. 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #ifndef _ADAFRUIT_ST7789H_ 19 | #define _ADAFRUIT_ST7789H_ 20 | 21 | #include "mbed.h" 22 | #include "Adafruit_GFX.h" 23 | 24 | #define boolean bool 25 | 26 | #define WIDTH 240 27 | #define HEIGHT 240 28 | 29 | #define ST7789_240x240_XSTART 0 30 | #define ST7789_240x240_YSTART 0 31 | 32 | #define ST_CMD_DELAY 0x80 // special signifier for command lists 33 | 34 | #define ST7789_NOP 0x00 35 | #define ST7789_SWRESET 0x01 36 | #define ST7789_RDDID 0x04 37 | #define ST7789_RDDST 0x09 38 | 39 | #define ST7789_SLPIN 0x10 40 | #define ST7789_SLPOUT 0x11 41 | #define ST7789_PTLON 0x12 42 | #define ST7789_NORON 0x13 43 | 44 | #define ST7789_INVOFF 0x20 45 | #define ST7789_INVON 0x21 46 | #define ST7789_DISPOFF 0x28 47 | #define ST7789_DISPON 0x29 48 | #define ST7789_CASET 0x2A 49 | #define ST7789_RASET 0x2B 50 | #define ST7789_RAMWR 0x2C 51 | #define ST7789_RAMRD 0x2E 52 | 53 | #define ST7789_PTLAR 0x30 54 | #define ST7789_COLMOD 0x3A 55 | #define ST7789_MADCTL 0x36 56 | 57 | #define ST7789_MADCTL_MY 0x80 58 | #define ST7789_MADCTL_MX 0x40 59 | #define ST7789_MADCTL_MV 0x20 60 | #define ST7789_MADCTL_ML 0x10 61 | #define ST7789_MADCTL_RGB 0x00 62 | 63 | #define ST7789_RDID1 0xDA 64 | #define ST7789_RDID2 0xDB 65 | #define ST7789_RDID3 0xDC 66 | #define ST7789_RDID4 0xDD 67 | 68 | 69 | class Adafruit_ST7789 : public Adafruit_GFX { 70 | 71 | public: 72 | 73 | Adafruit_ST7789(PinName mosi, PinName miso, PinName sck, PinName CS, PinName RS, PinName RST); 74 | 75 | void init(void); 76 | void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); 77 | void pushColor(uint16_t color); 78 | 79 | void fillScreen(uint16_t color); 80 | void drawPixel(int16_t x, int16_t y, uint16_t color); 81 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 82 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 83 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 84 | void invertDisplay(boolean i); 85 | 86 | void setRotation(uint8_t r); 87 | uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); 88 | 89 | private: 90 | uint8_t tabcolor; 91 | void spiwrite(uint8_t), 92 | writecommand(uint8_t c), 93 | writedata(uint8_t d), 94 | commandList(uint8_t *addr), 95 | commonInit(uint8_t *cmdList); 96 | 97 | SPI lcdPort; // does SPI MOSI, MISO and SCK 98 | DigitalOut _cs; // does SPI CE 99 | DigitalOut _rs; // register/date select 100 | DigitalOut _rst; // does 3310 LCD_RST 101 | }; 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /drivers/Adafruit_ST7789/README.md: -------------------------------------------------------------------------------- 1 | Vendored from https://os.mbed.com/users/srj17/code/Adafruit_ST7789/ at revision 8:266e25a75299 -------------------------------------------------------------------------------- /drivers/BMA42x_Accelerometer/README.md: -------------------------------------------------------------------------------- 1 | # BMA4xy Sensor API 2 | ## Introduction 3 | This package contains Bosch Sensortec's BMA4xy accelerometer family's sensor API 4 | 5 | ## Sensor API Revisions 6 | Files | Revision | Release date 7 | --------------|----------|------------- 8 | bma4_defs.h | 2.1.9 | 2017.10.12 9 | bma4.h | 2.1.9 | 2017.10.12 10 | bma4.c | 2.1.9 | 2017.10.12 11 | bma423.h | 1.1.4 | 2017.10.12 12 | bma423.c | 1.1.4 | 2017.10.12 13 | 14 | ## Sensor API integration 15 | 16 | Inside your project, include the common files *bma4_defs.h*, *bma4.h*, *bma4.c* and the variant specific source and include, *bma4xy.c* and *bma4xy.h*. 17 | 18 | In your code, include the variant specific header *bma4xy.h* 19 | 20 | ``` c 21 | #include "bma422.h" 22 | ``` 23 | 24 | ## User guide 25 | 26 | ### Initializing sequence 27 | First application setup examples algorithms: 28 | After correct power up by setting the correct voltage to the appropriate external pins, the 29 | BMA421 enters automatically into the Power On Reset (POR) sequence. In order to properly 30 | make use of the BMA421, certain steps from host processor side are needed. 31 | a. Reading the chip id. 32 | b. Performing initialization sequence. 33 | c. Checking the correct status of the interrupt feature engine. 34 | 35 | ``` c 36 | #include "bma421.h" 37 | 38 | uint16_t main(void) { 39 | uint16_t rslt = BMA4_OK; 40 | uint8_t init_seq_status = 0; 41 | 42 | /* Declare an instance of the BMA4xy device */ 43 | struct bma4_dev dev; 44 | 45 | /* Modify the parameters */ 46 | dev.dev_addr = BMA4_I2C_ADDR_PRIMARY; 47 | dev.interface = BMA4_I2C_INTERFACE; 48 | dev.bus_read = USER_i2c_read; 49 | dev.bus_write = USER_i2c_write; 50 | dev.delay = USER_delay_ms; 51 | dev.read_write_len = 8; 52 | dev.resolution = 12; 53 | dev.feature_len = BMA421_FEATURE_SIZE; 54 | 55 | /* a. Reading the chip id. */ 56 | rslt |= bma421_init(&dev); 57 | 58 | /* b. Performing initialization sequence. 59 | c. Checking the correct status of the initialization sequence. 60 | */ 61 | rslt |= bma421_write_config_file(&dev); 62 | 63 | return rslt; 64 | } 65 | ``` 66 | 67 | ### Sensor API initialization for the I2C protocol 68 | ``` c 69 | #include "bma422.h" 70 | 71 | uint16_t main(void) { 72 | uint16_t rslt = BMA4_OK; 73 | 74 | /* Declare an instance of the BMA4xy device */ 75 | struct bma4_dev accel; 76 | 77 | /* Modify the parameters */ 78 | accel.dev_addr = BMA4_I2C_ADDR_PRIMARY; 79 | accel.interface = BMA4_I2C_INTERFACE; 80 | accel.bus_read = USER_i2c_read; 81 | accel.bus_write = USER_i2c_write; 82 | accel.delay = USER_delay_ms; 83 | accel.read_write_len = 8; 84 | 85 | /* Initialize the instance */ 86 | rslt |= bma422_init(&accel); 87 | 88 | return rslt; 89 | } 90 | ``` 91 | 92 | ### Configuring the accelerometer 93 | ``` c 94 | #include "bma422.h" 95 | 96 | uint16_t main(void) { 97 | uint16_t rslt = BMA4_OK; 98 | 99 | /* Initialize the device instance as per the initialization example */ 100 | 101 | /* Enable the accelerometer */ 102 | bma4_set_accel_enable(ACCEL_ENABLE, dev); 103 | 104 | /* Declare an accelerometer configuration structure */ 105 | struct bma4_accel_config accel_conf; 106 | 107 | /* Assign the desired settings */ 108 | accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ; 109 | accel_conf.range = BMA4_ACCEL_RANGE_2G; 110 | accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4; 111 | accel_conf.perf_mode = BMA4_CONTINUOUS_MODE; 112 | 113 | /* Set the configuration */ 114 | rslt |= bma4_set_accel_config(&accel_conf, &accel); 115 | 116 | return rslt; 117 | } 118 | ``` 119 | 120 | ### Reading out the accelerometer data 121 | ``` c 122 | #include "bma422.h" 123 | 124 | uint16_t main(void) { 125 | uint16_t rslt = BMA4_OK; 126 | 127 | /* Initialize the device instance as per the initialization example */ 128 | 129 | /* Configure the accelerometer */ 130 | 131 | /* Declare an instance of the sensor data structure */ 132 | struct bma4_accel sens_data; 133 | 134 | /* Loop forever */ 135 | while (1) { 136 | /* Read the sensor data into the sensor data instance */ 137 | rslt |= bma4_read_accel_xyz(&sens_data, &accel); 138 | 139 | /* Exit the program in case of a failure */ 140 | if (rslt != BMA4_OK) 141 | return rslt; 142 | 143 | /* Use the data */ 144 | printf("X: %d, Y: %d, Z: %d\n", sens_data.x, sens_data.y, sens_data.z); 145 | 146 | /* Pause for 10ms, 100Hz output data rate */ 147 | USER_delay_ms(10); 148 | } 149 | 150 | return rslt; 151 | } 152 | ``` 153 | 154 | ### Configuring reading out sensor data from the FIFO buffer 155 | ``` c 156 | #include "bma422.h" 157 | 158 | uint16_t main(void) { 159 | uint16_t rslt = BMA4_OK; 160 | 161 | /* Initialize the device instance as per the initialization example */ 162 | 163 | /* Configure the accelerometer */ 164 | 165 | /* Setup and configure the FIFO buffer */ 166 | /* Declare memory to store the raw FIFO buffer information */ 167 | uint8_t fifo_buff[255]; 168 | struct bma4_fifo_frame fifo_frame; 169 | 170 | /* Modify the FIFO buffer instance and link to the device instance */ 171 | fifo_frame.data = fifo_buff; 172 | fifo_frame.length = 255; 173 | fifo_frame.fifo_data_enable = BMA4_ENABLE; 174 | fifo_frame.fifo_header_enable = BMA4_ENABLE; 175 | accel.fifo = &fifo_frame; 176 | 177 | /* Disable the advanced power save mode to configure the FIFO buffer */ 178 | rslt |= bma4_set_advance_power_save(BMA4_DISABLE, &accel); 179 | 180 | /* Configure the FIFO buffer */ 181 | rslt |= bma4_set_fifo_config((BMA4_FIFO_ACCEL | BMA4_FIFO_HEADER), BMA4_ENABLE, &accel); 182 | 183 | /* Declare instances of the sensor data structure */ 184 | struct bma4_accel sens_data[36]; // 255 bytes / ~7bytes per frame = 36 instances 185 | uint16_t n_instances, i; 186 | 187 | /* Loop forever */ 188 | while (1) { 189 | /* Read data from the sensor FIFO buffer */ 190 | rslt |= bma4_read_fifo_data(&accel); // Read FIFO data 191 | 192 | /* Exit the program in case of a failure */ 193 | if (rslt != BMA4_OK) 194 | return rslt; 195 | 196 | /* Reset the maximum number of requried sensor data instances */ 197 | n_instances = 36; 198 | 199 | /* Parse the FIFO until there are less frames than requested */ 200 | while (n_instances == 36) { 201 | /* Parse the FIFO buffer and extract requried number of accelerometer data frames */ 202 | rslt |= bma4_extract_accel(sens_data, &n_instances, &accel); 203 | 204 | /* Exit the program in case of a failure */ 205 | if (rslt != BMA4_OK) 206 | return rslt; 207 | 208 | /* Use the accelerometer data frames */ 209 | for (i = 0; i < n_instances; i++) 210 | printf("X:%d, Y:%d, Z:%d\n", sens_data[i].x, sens_data[i].y, sens_data[i].z); 211 | } 212 | 213 | // At 100Hz, The FIFO buffer will have 36 frames ready in (1 / 100) * 36 = ~0.36s 214 | USER_delay_ms(360); 215 | } 216 | 217 | return rslt; 218 | } 219 | ``` 220 | 221 | ### Enabling and mapping line interrupt to that of BMA422 sensor interrupt 222 | 223 | This example shows mapping of a line interrupt with two feature interrupts simultaneously in 224 | variant BMA422. 225 | Note: There are two interrupts - feature interrupt and hardware interrupts. You can map more 226 | than one interrupt with a single line interrupt. If a feature interrupt is mapped with a line 227 | interrupt, one can map the other line interrupt with that of hardware interrupt. This example 228 | can be done for other variants as well. 229 | ``` c 230 | #include "bma422.h" 231 | 232 | uint16_t main(void) 233 | { 234 | uint16_t result = BMA4_OK; 235 | /* Variable to define two interrupt lines */ 236 | uint8_t int_line[2] = {BMA4_INTR1_MAP, BMA4_INTR2_MAP}; 237 | /* Variable to define feature interrupts to be mapped*/ 238 | uint16_t int_map = (BMA422_STEP_CNTR_INT | BMA422_WAKEUP_INT); 239 | 240 | /* Initialize the device instance as per the initialization example */ 241 | 242 | /* Configure the accelerometer as per the example */ 243 | 244 | /* Mapping line interrupt 1 with that of two sensor feature interrupts - 245 | * Step counter and wake up interrupt */ 246 | result = bma422_map_interrupt(int_line[0], int_map, BMA4_ENABLE, dev); 247 | 248 | if(result == BMA4_OK) { 249 | printf("Interrupt mapping successful\r\n"); 250 | } 251 | else { 252 | printf("Interrupt mapping failed\r\n"); 253 | printf("Error code = %d\r\n", result); 254 | } 255 | 256 | return result; 257 | } 258 | ``` 259 | 260 | ### Reading interrupt status register 261 | This example is in continuation of the previous example: Enabling and mapping line interrupt. 262 | After the interrupts are mapped, interrupt status register is read in an interrupt service 263 | routine to perform the corresponding tasks on an interrupt. 264 | ``` c 265 | #include "bma422.h" 266 | 267 | void interrupt_handler(void) 268 | { 269 | uint16_t result = BMA4_OK; 270 | /* Define a variable to get the status */ 271 | uint16_t int_status = 0; 272 | 273 | /* Read the interrupt status register */ 274 | result = bma422_read_int_status(&int_status, dev) 275 | 276 | if(result == BMA4_OK) { 277 | 278 | if(int_status & BMA422_STEP_CNTR_INT) { 279 | 280 | /* Call the function to be performed on step counter interrupt */ 281 | 282 | } else if(int_status & BMA422_WAKEUP_INT) { 283 | 284 | /* Call the function to be performed on wake up interrupt */ 285 | } 286 | } 287 | ``` 288 | ### Configuring the auxiliary sensor BMM150 289 | 290 | ### Initialization of auxiliary interface to access BMM150 291 | ``` 292 | /* Structure declaration */ 293 | struct bma4_dev *dev; 294 | 295 | /* Switch on the the auxiliary interface mode */ 296 | dev->aux_config.if_mode = BMA4_ENABLE_AUX_IF_MODE; 297 | /* Set the I2C device address of auxiliary device */ 298 | /* Device address of BMM150 */ 299 | dev->aux_config.aux_dev_addr = BMA4_I2C_BMM150_ADDR; 300 | /* Set aux interface to manual mode */ 301 | dev->aux_config.manual_enable = BMA4_MANUAL_ENABLE; 302 | /* Set the number of bytes for burst read */ 303 | dev->aux_config.burst_read_length = BMA4_AUX_READ_LEN_0; 304 | 305 | /* Initialize the auxiliary interface */ 306 | bma4_aux_interface_init(&sensor); 307 | ``` 308 | ### Reading of data from auxiliary sensor BMM150 309 | Initialize the auxiliary interface as shown above. Set the power mode to sleep mode and the operation mode 310 | to forced mode. Then validate the sensor by reading the chip id. 311 | 312 | ``` 313 | uint8_t aux_data[5] = {0}; 314 | uint8_t aux_chip_id = 0; 315 | uint8_t aux_write; 316 | 317 | /* Enable the power control bit for sleep mode in 0x4B register of BMM150 */ 318 | aux_write = 0x01; 319 | result |= bma4_aux_write(0x4B, &aux_write, 1, dev); 320 | 321 | /* Enable forced mode in 0x4C register of BMM150 */ 322 | aux_write = 0x02; 323 | result |= bma4_aux_write(0x4c, &aux_write, 1, dev); 324 | 325 | /* Read the chip-id of the auxiliary sensor */ 326 | result = bma4_aux_read(BMA4_AUX_CHIP_ID_ADDR, &aux_chip_id, 1, dev); 327 | if(aux_chip_id == BMM150_CHIP_ID) { 328 | result = bma4_aux_read(aux_read_addr, aux_data, 1, dev); 329 | } 330 | ``` 331 | 332 | ### Writing of data from auxiliary sensor BMM150 333 | Initialize the auxiliary interface as shown above. Set the power mode to sleep mode and the operation mode 334 | to forced mode. Then validate the sensor by reading the chip id before writing.. 335 | 336 | ``` 337 | uint8_t aux_write_data[5] = {0xFF, 0xAA, 0xFD, 0x78, 0x99}; 338 | uint8_t aux_chip_id = 0; 339 | uint8_t aux_write; 340 | 341 | /* Enable the power control bit for sleep mode in 0x4B register of BMM150 */ 342 | aux_write = 0x01; 343 | result |= bma4_aux_write(0x4B, &aux_write, 1, dev); 344 | 345 | /* Enable forced mode in 0x4C register of BMM150 */ 346 | aux_write = 0x02; 347 | result |= bma4_aux_write(0x4c, &aux_write, 1, dev); 348 | 349 | /* Read the chip-id of the auxiliary sensor */ 350 | result = bma4_aux_read(BMA4_AUX_CHIP_ID_ADDR, &aux_chip_id, 1, dev); 351 | if(aux_chip_id == BMM150_CHIP_ID) { 352 | result = bma4_aux_write(0x50, aux_write_data, 4, dev); 353 | } 354 | 355 | ``` 356 | 357 | ### Accessing of auxiliary sensor BMM150 with the help of BMM150 APIs via BMA4 secondary interface. 358 | User has to create a wrapper function over bma4_aux_read and bma4_aux_write in order to map with 359 | bmi150 read and write 360 | 361 | ``` 362 | /* Structure declaration */ 363 | struct bmm150_dev bmm150; 364 | 365 | /* function declaration */ 366 | int8_t bma4_user_aux_read(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len); 367 | int8_t bma4_user_aux_write(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len); 368 | 369 | /* Update bmm150 structure */ 370 | bmm150.read = bma4_user_aux_read; 371 | bmm150.write = bma4_user_aux_write; 372 | bmm150.id = BMM150_DEFAULT_I2C_ADDRESS; 373 | bmm150.delay_ms = delay_ms; 374 | bmm150.interface = BMM150_I2C_INTF; 375 | 376 | /* Initialize bmm150 sensor */ 377 | bmm150_init(bmm150); 378 | ``` 379 | 380 | ### Wrapper functions for auxiliary read and write 381 | 382 | ``` 383 | /* Wrapper function to map bmm150.read */ 384 | int8_t bma4_user_aux_read(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len) 385 | { 386 | int8_t result; 387 | 388 | if (dev->aux_config.aux_dev_addr == id) 389 | result = bma4_aux_read(reg_addr, aux_data, len, dev); 390 | 391 | return result; 392 | } 393 | 394 | /* Wrapper function to map bmm150.write */ 395 | int8_t bma4_user_aux_write(uint8_t id, uint8_t reg_addr, uint8_t *aux_data, uint16_t len) 396 | { 397 | int8_t result; 398 | 399 | if (dev->aux_config.aux_dev_addr == id) 400 | result = bma4_aux_write(reg_addr, aux_data, len, dev); 401 | 402 | return result; 403 | } 404 | ``` 405 | 406 | ### Get temperature from BMA4 sensor, eg., BMA422 407 | A scaling factor of 1000 has to be used to convert the read temperature back to its 408 | float value. 409 | 410 | ``` 411 | void main() 412 | { 413 | int8_t rslt; 414 | int32_t get_temp_C = 0; 415 | int32_t get_temp_F = 0; 416 | int32_t get_temp_K = 0; 417 | float actual_temp = 0; 418 | 419 | /* Initialize bma4 sensor to get the chip id */ 420 | rslt = bma4_init(dev); 421 | 422 | if(rslt == BMA4_OK) { 423 | if(dev->chip_id == BMA422_CHIP_ID) { 424 | rslt = bma422_init(dev); 425 | 426 | if(rslt == BMA4_OK) { 427 | /* Reset the accelerometer */ 428 | bma4_set_command_register(0xB6, dev); 429 | dev->delay(1); 430 | 431 | /* Enable the accelerometer */ 432 | rslt = bma4_set_accel_enable(1, dev); 433 | dev->delay(10); 434 | 435 | /* Get temperature in degree C */ 436 | rslt = bma4_get_temperature(&get_temp_C, BMA4_DEG, dev); 437 | /* Get temperature in degree F */ 438 | rslt = bma4_get_temperature(&get_temp_F, BMA4_FAHREN, dev); 439 | /* Get temperature in degree K */ 440 | rslt = bma4_get_temperature(&get_temp_K, BMA4_KELVIN, dev); 441 | 442 | /* Divide the temperature read with the scaling factor to get 443 | the actual temperature */ 444 | if(rslt == BMA4_OK) { 445 | actual_temp = (float)get_temp_C / (float)BMA4_SCALE_TEMP; 446 | printf("Actual temperature in degree celsius is %10.2f degrees C\r\n", actual_temp); 447 | 448 | actual_temp = (float)get_temp_F / (float)BMA4_SCALE_TEMP; 449 | printf("Actual temperature in degree fahranheit is %10.2f degrees F\r\n", actual_temp); 450 | 451 | actual_temp = (float)get_temp_K / (float)BMA4_SCALE_TEMP; 452 | printf("Actual temperature in degree kelvin is %10.2f degrees K\r\n", actual_temp); 453 | 454 | /* 0x80 - temp read from the register and 23 is the ambient temp added. 455 | * If the temp read from register is 0x80, it means no valid 456 | * information is available */ 457 | if(((get_temp_C - 23) / BMA4_SCALE_TEMP) == 0x80) { 458 | printf("No valid temperature information available\r\n"); 459 | } 460 | } 461 | } 462 | } 463 | } 464 | } 465 | ``` 466 | ### Selection of Any-motion and No-motion feature. 467 | This snippet of code reflects that how to switch between any-motion and no-motion. 468 | Given snippet of code is for BMA421 sensor. Same steps are applicable for others sensors. 469 | 470 | ``` 471 | /* Enable/select the no-motion feature */ 472 | bma421_feature_enable(BMA421_NO_MOTION, 1, dev); 473 | 474 | /*Enable the axis as per requirement for Any/no-motion. Here all axis has been enabled */ 475 | bma421_anymotion_enable_axis(BMA421_ALL_AXIS_EN, dev); 476 | 477 | /* Enable/select the Any-motion feature */ 478 | bma421_feature_enable(BMA421_ANY_MOTION, 1, dev); 479 | 480 | ``` 481 | 482 | ### Activity(still/walking/running/invalid) recognition. 483 | 484 | ``` 485 | /* Enable the activity feature */ 486 | rslt = bma421_feature_enable(BMA421_ACTIVITY, 1, dev); 487 | 488 | /* Map the activity out interupt to INT pin1 */ 489 | bma421_map_interrupt(BMA4_INTR1_MAP,BMA421_ACTIVITY_INT, BMA4_ENABLE, dev); 490 | 491 | ``` 492 | ### ISR for activity interrupt recognition 493 | ``` c 494 | uint16_t int_status = 0; 495 | uint8_t activity_out = 0; 496 | 497 | /* Read the Interrupt status reg. */ 498 | bma421_read_int_status(&int_status, dev); 499 | 500 | if(int_status & BMA421_ACTIVITY_INT) { 501 | /* Read the activity out register for user's activity*/ 502 | bma421_activity_output(&activity_out, dev); 503 | /* compare the output of activity register and perform the action as per requirement */ 504 | switch (activity_out) { 505 | 506 | case BMA421_USER_STATIONARY: 507 | /* User state is stationary */ 508 | /* Perform the respective action according to this state */ 509 | break; 510 | case BMA421_USER_WALKING: 511 | /* User state is walking */ 512 | /* Perform the respective action according to this state */ 513 | break; 514 | case BMA421_USER_RUNNING: 515 | /* User state is running */ 516 | /* Perform the respective action according to this state */ 517 | break; 518 | case BMA421_STATE_INVALID: 519 | /* User state is invalid */ 520 | /* Perform the respective action according to this state */ 521 | break; 522 | } 523 | } 524 | ``` 525 | 526 | ### Platform(wrist/phone) selection. 527 | Note:- Default configuration is wrist. 528 | ``` 529 | /* Select the phone configuration for the sensor */ 530 | bma421_select_platform(BMA421_PHONE_CONFIG, dev); 531 | 532 | /* Select the wrist configuration for the sensor */ 533 | bma421_select_platform(BMA421_WRIST_CONFIG, dev); 534 | 535 | ``` 536 | -------------------------------------------------------------------------------- /drivers/CST0xx_TouchPad/CST0xx_TouchPad.cpp: -------------------------------------------------------------------------------- 1 | #include "CST0xx_TouchPad.h" 2 | 3 | #include "platform/mbed_assert.h" 4 | 5 | #include "mbed-trace/mbed_trace.h" 6 | #define TRACE_GROUP "TCHP" 7 | 8 | #define CST0XX_I2C_ADDRESS 0x15 9 | 10 | #define HYN_TOUCH_EVENT_TYPE_POS 1 11 | #define HYN_TOUCH_X_H_POS 3 12 | #define HYN_TOUCH_X_L_POS 4 13 | #define HYN_TOUCH_Y_H_POS 5 14 | #define HYN_TOUCH_Y_L_POS 6 15 | 16 | void print_hex(uint8_t *string, uint32_t len) 17 | { 18 | tr_info("Dumping hex buffer of size %lu", len); 19 | for (unsigned int i = 0; i < len; ++i) 20 | { 21 | printf("0x%02x \r\n", string[i]); 22 | } 23 | printf("\n"); 24 | tr_info("End dump."); 25 | } 26 | 27 | CST0xx_TouchPad::CST0xx_TouchPad(mbed::I2C *i2c) : _i2c(i2c) 28 | { 29 | // TODO: Check Chip ID and firmware version on initalization. 30 | } 31 | 32 | CST0xx_TouchPad::CST0xx_TouchPad(mbed::I2C *i2c, 33 | mbed::Callback touch_event_callback) 34 | : _i2c(i2c), _touch_event_callback(touch_event_callback) 35 | { 36 | } 37 | 38 | void CST0xx_TouchPad::handle_interrupt() 39 | { 40 | uint8_t buf[7]; 41 | uint16_t ret = i2c_reg_read(0x15, 0x00, buf, 7); 42 | if (ret) 43 | { 44 | tr_err("Touch event: I2C Read returned: %u", ret); 45 | } 46 | 47 | struct ts_event data = {}; 48 | data.type = static_cast( 49 | buf[HYN_TOUCH_EVENT_TYPE_POS]); // TODO: Handle invalid event type. 50 | data.x = (uint16_t)(buf[HYN_TOUCH_X_H_POS] & 0x0F) << 8 | (uint16_t)buf[HYN_TOUCH_X_L_POS]; 51 | data.y = (uint16_t)(buf[HYN_TOUCH_Y_H_POS] & 0x0F) << 8 | (uint16_t)buf[HYN_TOUCH_Y_L_POS]; 52 | 53 | tr_debug("Touch event: Type %u. X: %u Y: %u", data.type, data.x, data.y); 54 | 55 | if (_touch_event_callback) 56 | { 57 | _touch_event_callback(data); 58 | } 59 | } 60 | 61 | uint16_t CST0xx_TouchPad::i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, 62 | uint16_t length) 63 | { 64 | /* Write to registers using I2C. Return 0 for a successful execution. */ 65 | int ret = 0; 66 | const int TEMP_BUF_SIZE = 32; 67 | if (length > TEMP_BUF_SIZE) 68 | { 69 | return -2; 70 | } 71 | uint8_t tmp[TEMP_BUF_SIZE]; 72 | tmp[0] = reg_addr; 73 | memcpy(tmp + 1, reg_data, length); 74 | 75 | ret = _i2c->write(i2c_addr << 1, (const char *)tmp, length + 1, false); 76 | 77 | if (!ret) 78 | { 79 | return 0; 80 | } 81 | tr_err("I2C Write Failed, returned %i", ret); 82 | return -1; 83 | } 84 | 85 | uint16_t CST0xx_TouchPad::i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, 86 | uint16_t length) 87 | { 88 | 89 | /* Read from registers using I2C. Return 0 for a successful execution. */ 90 | 91 | int ret = 0; 92 | 93 | ret = _i2c->write(i2c_addr << 1, (const char *)®_addr, 1, true); 94 | if (!ret) 95 | { 96 | ret = _i2c->read(i2c_addr << 1, (char *)reg_data, length, false); 97 | } 98 | else 99 | { 100 | tr_err("I2C Read Failed writting address, returned %i.", ret); 101 | } 102 | 103 | if (!ret) 104 | { 105 | return 0; 106 | } 107 | tr_err("I2C Read Failed, returned %i.", ret); 108 | return -1; 109 | } -------------------------------------------------------------------------------- /drivers/CST0xx_TouchPad/CST0xx_TouchPad.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CST0XXTOUCHPAD_H 3 | #define CST0XXTOUCHPAD_H 4 | 5 | #include "drivers/I2C.h" 6 | #include "platform/Callback.h" 7 | 8 | class CST0xx_TouchPad 9 | { 10 | public: 11 | enum event_type 12 | { 13 | EVENT_TYPE_TOUCH = 0x05, 14 | EVENT_TYPE_LONG_TOUCH = 0x0C, 15 | EVENT_TYPE_SWIPE_Y_POSITIVE = 0x01, 16 | EVENT_TYPE_SWIPE_Y_NEGATIVE = 0x02, 17 | EVENT_TYPE_SWIPE_X_NEGATIVE = 0x03, 18 | EVENT_TYPE_SWIPE_X_POSITIVE = 0x04 19 | }; 20 | 21 | struct ts_event 22 | { 23 | enum event_type type; 24 | uint16_t x; 25 | uint16_t y; 26 | }; 27 | 28 | CST0xx_TouchPad(mbed::I2C *i2c); 29 | CST0xx_TouchPad(mbed::I2C *i2c, mbed::Callback touch_event_callback); 30 | void handle_interrupt(); 31 | 32 | protected: 33 | mbed::I2C *_i2c; 34 | mbed::Callback _touch_event_callback; 35 | uint16_t i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 36 | uint16_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 37 | }; 38 | 39 | #endif // CST0XXTOUCHPAD_H 40 | -------------------------------------------------------------------------------- /drivers/HRS3300_HeartRateSensor/HRS3300_HeartRateSensor.cpp: -------------------------------------------------------------------------------- 1 | #include "HRS3300_HeartRateSensor.h" 2 | 3 | #include "platform/mbed_assert.h" 4 | 5 | #include "mbed-trace/mbed_trace.h" 6 | #define TRACE_GROUP "HRS" 7 | 8 | HRS3300_HeartRateSensor::HRS3300_HeartRateSensor(mbed::I2C *i2c) : _i2c(i2c) 9 | { 10 | uint8_t charbuf = 0; 11 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_ID, &charbuf, 1); 12 | MBED_ASSERT(charbuf == HRS3300_DEVICE_ID); 13 | 14 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_RESOLUTION, &charbuf, 1); 15 | tr_info("res: 0x%hu", charbuf); 16 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_HGAIN, &charbuf, 1); 17 | tr_info("gain: 0x%hu", charbuf); 18 | 19 | set_enable(); 20 | set_adc_resolution(); 21 | set_hrs_gain(); 22 | } 23 | 24 | void HRS3300_HeartRateSensor::set_enable(enum HRS_ENABLE_DISABLE enable, 25 | enum HRS_WAIT_TIME wait_time, enum PDRIVE_CURRENT current, 26 | enum HRS_ENABLE_DISABLE p_on) 27 | { 28 | uint8_t charbuf = 0; 29 | 30 | charbuf = charbuf | enable << 7; 31 | charbuf = charbuf | wait_time << 4; 32 | charbuf = charbuf | (current & (1 << 1)) << 2; 33 | i2c_reg_write(HRS3300_I2C_ADDRESS, HRS3300_REG_ENABLE, &charbuf, 1); 34 | 35 | charbuf = 0; 36 | charbuf = charbuf | (current & 1) << 6; 37 | charbuf = charbuf | p_on << 5; 38 | charbuf = charbuf | 1 << 3; // This bit is set by default. Not sure if it needs to be set. 39 | i2c_reg_write(HRS3300_I2C_ADDRESS, HRS3300_REG_PDRIVER, &charbuf, 1); 40 | } 41 | 42 | void HRS3300_HeartRateSensor::set_adc_resolution(enum ADC_RESOLUTION resolution) 43 | { 44 | uint8_t charbuf = 0x60; // Default value is 0x66, not sure what the other bits do. 45 | charbuf = charbuf | resolution; 46 | i2c_reg_write(HRS3300_I2C_ADDRESS, HRS3300_REG_RESOLUTION, &charbuf, 1); 47 | } 48 | 49 | void HRS3300_HeartRateSensor::set_hrs_gain(enum HRS_GAIN gain) 50 | { 51 | uint8_t charbuf = 0; 52 | charbuf = charbuf | gain << 2; 53 | i2c_reg_write(HRS3300_I2C_ADDRESS, HRS3300_REG_HGAIN, &charbuf, 1); 54 | } 55 | 56 | uint32_t HRS3300_HeartRateSensor::read_heart_rate_sensor() 57 | { 58 | uint32_t ret_val = 0; 59 | uint8_t charbuf = 0; 60 | 61 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_C0DATAL, &charbuf, 1); 62 | ret_val = ret_val | charbuf; 63 | 64 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_C0DATAM, &charbuf, 1); 65 | ret_val = ret_val | charbuf << 8; 66 | 67 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_C0DATAH, &charbuf, 1); 68 | ret_val = ret_val | charbuf << 16; 69 | 70 | return ret_val; 71 | } 72 | 73 | uint32_t HRS3300_HeartRateSensor::read_ambient_light_sensor() 74 | { 75 | uint32_t ret_val = 0; 76 | uint8_t charbuf = 0; 77 | 78 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_C1DATAL, &charbuf, 1); 79 | ret_val = ret_val | charbuf; 80 | 81 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_C1DATAM, &charbuf, 1); 82 | ret_val = ret_val | charbuf << 8; 83 | 84 | i2c_reg_read(HRS3300_I2C_ADDRESS, HRS3300_REG_C1DATAH, &charbuf, 1); 85 | ret_val = ret_val | charbuf << 16; 86 | 87 | return ret_val; 88 | } 89 | 90 | uint16_t HRS3300_HeartRateSensor::i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, 91 | uint8_t *reg_data, uint16_t length) 92 | { 93 | 94 | /* Write to registers using I2C. Return 0 for a successful execution. */ 95 | int ret = 0; 96 | const int TEMP_BUF_SIZE = 32; 97 | if (length > TEMP_BUF_SIZE) 98 | { 99 | return -2; 100 | } 101 | uint8_t tmp[TEMP_BUF_SIZE]; 102 | tmp[0] = reg_addr; 103 | memcpy(tmp + 1, reg_data, length); 104 | 105 | ret = _i2c->write(i2c_addr << 1, (const char *)tmp, length + 1, false); 106 | 107 | if (!ret) 108 | { 109 | return 0; 110 | } 111 | tr_err("I2C Write Failed, returned %i", ret); 112 | return -1; 113 | } 114 | 115 | uint16_t HRS3300_HeartRateSensor::i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, 116 | uint8_t *reg_data, uint16_t length) 117 | { 118 | 119 | /* Read from registers using I2C. Return 0 for a successful execution. */ 120 | 121 | int ret = 0; 122 | 123 | ret = _i2c->write(i2c_addr << 1, (const char *)®_addr, 1, true); 124 | if (!ret) 125 | { 126 | ret = _i2c->read(i2c_addr << 1, (char *)reg_data, length, false); 127 | } 128 | else 129 | { 130 | tr_err("I2C Read Failed writting address, returned %i.", ret); 131 | } 132 | 133 | if (!ret) 134 | { 135 | return 0; 136 | } 137 | tr_err("I2C Read Failed, returned %i.", ret); 138 | return -1; 139 | } -------------------------------------------------------------------------------- /drivers/HRS3300_HeartRateSensor/HRS3300_HeartRateSensor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HRS3300HEARTRATESENSOR_H 3 | #define HRS3300HEARTRATESENSOR_H 4 | 5 | #include "drivers/I2C.h" 6 | 7 | #define HRS3300_I2C_ADDRESS 0x44 8 | #define HRS3300_DEVICE_ID 0x21 9 | 10 | #define HRS3300_REG_ID 0x00 11 | #define HRS3300_REG_ENABLE 0x01 12 | #define HRS3300_REG_PDRIVER 0x0C 13 | 14 | #define HRS3300_REG_C0DATAL 0x0F 15 | #define HRS3300_REG_C0DATAM 0x09 16 | #define HRS3300_REG_C0DATAH 0x0A 17 | 18 | #define HRS3300_REG_C1DATAL 0x0E 19 | #define HRS3300_REG_C1DATAM 0x08 20 | #define HRS3300_REG_C1DATAH 0x0D 21 | 22 | #define HRS3300_REG_RESOLUTION 0x16 23 | #define HRS3300_REG_HGAIN 0x17 24 | 25 | class HRS3300_HeartRateSensor 26 | { 27 | public: 28 | enum HRS_WAIT_TIME 29 | { 30 | HRS_WAIT_TIME_800ms = 0, 31 | HRS_WAIT_TIME_400ms = 1, 32 | HRS_WAIT_TIME_200ms = 2, 33 | HRS_WAIT_TIME_100ms = 3, 34 | HRS_WAIT_TIME_75ms = 4, 35 | HRS_WAIT_TIME_50ms = 5, 36 | HRS_WAIT_TIME_12_5ms = 6, 37 | HRS_WAIT_TIME_0ms = 7 38 | }; 39 | 40 | enum HRS_ENABLE_DISABLE 41 | { 42 | HRS_DISABLE = 0, 43 | HRS_ENABLE = 1 44 | 45 | }; 46 | 47 | enum PDRIVE_CURRENT 48 | { 49 | PDRIVE_CURRENT_12_5mA = 0, 50 | PDRIVE_CURRENT_20mA = 1, 51 | PDRIVE_CURRENT_30mA = 2, 52 | PDRIVE_CURRENT_40mA = 3 53 | }; 54 | 55 | enum ADC_RESOLUTION 56 | { 57 | ADC_RESOLUTION_8b = 0, 58 | ADC_RESOLUTION_9b = 1, 59 | ADC_RESOLUTION_10b = 2, 60 | ADC_RESOLUTION_11b = 3, 61 | ADC_RESOLUTION_12b = 4, 62 | ADC_RESOLUTION_13b = 5, 63 | ADC_RESOLUTION_14b = 6, 64 | ADC_RESOLUTION_15b = 7, 65 | ADC_RESOLUTION_16b = 8, 66 | ADC_RESOLUTION_17b = 9, 67 | ADC_RESOLUTION_18b = 10, 68 | }; 69 | 70 | enum HRS_GAIN 71 | { 72 | HRS_GAIN_1x = 0, 73 | HRS_GAIN_2x = 1, 74 | HRS_GAIN_4x = 2, 75 | HRS_GAIN_8x = 3, 76 | HRS_GAIN_64x = 4 77 | }; 78 | 79 | HRS3300_HeartRateSensor(mbed::I2C *i2c); 80 | 81 | void set_enable(enum HRS_ENABLE_DISABLE enable = HRS_DISABLE, 82 | enum HRS_WAIT_TIME wait_time = HRS_WAIT_TIME_12_5ms, 83 | enum PDRIVE_CURRENT current = PDRIVE_CURRENT_40mA, 84 | enum HRS_ENABLE_DISABLE p_on = HRS_ENABLE); 85 | void set_adc_resolution(enum ADC_RESOLUTION resolution = ADC_RESOLUTION_14b); 86 | void set_hrs_gain(enum HRS_GAIN gain = HRS_GAIN_64x); 87 | uint32_t read_heart_rate_sensor(); 88 | uint32_t read_ambient_light_sensor(); 89 | 90 | protected: 91 | mbed::I2C *_i2c; 92 | uint16_t i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 93 | uint16_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, uint16_t length); 94 | }; 95 | 96 | #endif // HRS3300HEARTRATESENSOR_H 97 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Examples/Main_RTT_InputEchoApp.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | 12 | --------- END-OF-HEADER -------------------------------------------- 13 | File : Main_RTT_MenuApp.c 14 | Purpose : Sample application to demonstrate RTT bi-directional functionality 15 | */ 16 | 17 | #define MAIN_C 18 | 19 | #include 20 | 21 | #include "SEGGER_RTT.h" 22 | 23 | volatile int _Cnt; 24 | volatile int _Delay; 25 | 26 | static char r; 27 | 28 | /********************************************************************* 29 | * 30 | * main 31 | */ 32 | void main(void) { 33 | 34 | SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n"); 35 | SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP); 36 | do { 37 | r = SEGGER_RTT_WaitKey(); 38 | SEGGER_RTT_Write(0, &r, 1); 39 | r++; 40 | } while (1); 41 | } 42 | 43 | /*************************** End of file ****************************/ 44 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Examples/Main_RTT_MenuApp.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | --------- END-OF-HEADER -------------------------------------------- 12 | File : Main_RTT_MenuApp.c 13 | Purpose : Sample application to demonstrate RTT bi-directional functionality 14 | */ 15 | 16 | #define MAIN_C 17 | 18 | #include 19 | 20 | #include "SEGGER_RTT.h" 21 | 22 | volatile int _Cnt; 23 | volatile int _Delay; 24 | 25 | /********************************************************************* 26 | * 27 | * main 28 | */ 29 | void main(void) { 30 | int r; 31 | int CancelOp; 32 | 33 | do { 34 | _Cnt = 0; 35 | 36 | SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n"); 37 | SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n"); 38 | SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n"); 39 | do { 40 | r = SEGGER_RTT_WaitKey(); 41 | } while ((r != '1') && (r != '2')); 42 | if (r == '1') { 43 | SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n"); 44 | SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL); 45 | } else { 46 | SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n"); 47 | SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP); 48 | } 49 | CancelOp = 0; 50 | do { 51 | //for (_Delay = 0; _Delay < 10000; _Delay++); 52 | SEGGER_RTT_printf(0, "Count: %d. Press to get back to menu.\r\n", _Cnt++); 53 | r = SEGGER_RTT_HasKey(); 54 | if (r) { 55 | CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0; 56 | } 57 | // 58 | // Check if user selected to cancel the current operation 59 | // 60 | if (CancelOp) { 61 | SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n"); 62 | break; 63 | } 64 | } while (1); 65 | SEGGER_RTT_GetKey(); 66 | SEGGER_RTT_WriteString(0, "\r\n"); 67 | } while (1); 68 | } 69 | 70 | /*************************** End of file ****************************/ 71 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Examples/Main_RTT_PrintfTest.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | 12 | --------- END-OF-HEADER -------------------------------------------- 13 | File : Main_RTT_MenuApp.c 14 | Purpose : Sample application to demonstrate RTT bi-directional functionality 15 | */ 16 | 17 | #define MAIN_C 18 | 19 | #include 20 | 21 | #include "SEGGER_RTT.h" 22 | 23 | volatile int _Cnt; 24 | 25 | /********************************************************************* 26 | * 27 | * main 28 | */ 29 | void main(void) { 30 | 31 | SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL); 32 | 33 | SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n"); 34 | SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n"); 35 | 36 | SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S'); 37 | SEGGER_RTT_printf(0, "printf Test: %%5c, 'E' : %5c.\r\n", 'E'); 38 | SEGGER_RTT_printf(0, "printf Test: %%-5c, 'G' : %-5c.\r\n", 'G'); 39 | SEGGER_RTT_printf(0, "printf Test: %%5.3c, 'G' : %-5c.\r\n", 'G'); 40 | SEGGER_RTT_printf(0, "printf Test: %%.3c, 'E' : %-5c.\r\n", 'E'); 41 | SEGGER_RTT_printf(0, "printf Test: %%c, 'R' : %c.\r\n", 'R'); 42 | 43 | SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\" : %s.\r\n", "RTT"); 44 | SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks."); 45 | 46 | SEGGER_RTT_printf(0, "printf Test: %%u, 12345 : %u.\r\n", 12345); 47 | SEGGER_RTT_printf(0, "printf Test: %%+u, 12345 : %+u.\r\n", 12345); 48 | SEGGER_RTT_printf(0, "printf Test: %%.3u, 12345 : %.3u.\r\n", 12345); 49 | SEGGER_RTT_printf(0, "printf Test: %%.6u, 12345 : %.6u.\r\n", 12345); 50 | SEGGER_RTT_printf(0, "printf Test: %%6.3u, 12345 : %6.3u.\r\n", 12345); 51 | SEGGER_RTT_printf(0, "printf Test: %%8.6u, 12345 : %8.6u.\r\n", 12345); 52 | SEGGER_RTT_printf(0, "printf Test: %%08u, 12345 : %08u.\r\n", 12345); 53 | SEGGER_RTT_printf(0, "printf Test: %%08.6u, 12345 : %08.6u.\r\n", 12345); 54 | SEGGER_RTT_printf(0, "printf Test: %%0u, 12345 : %0u.\r\n", 12345); 55 | SEGGER_RTT_printf(0, "printf Test: %%-.6u, 12345 : %-.6u.\r\n", 12345); 56 | SEGGER_RTT_printf(0, "printf Test: %%-6.3u, 12345 : %-6.3u.\r\n", 12345); 57 | SEGGER_RTT_printf(0, "printf Test: %%-8.6u, 12345 : %-8.6u.\r\n", 12345); 58 | SEGGER_RTT_printf(0, "printf Test: %%-08u, 12345 : %-08u.\r\n", 12345); 59 | SEGGER_RTT_printf(0, "printf Test: %%-08.6u, 12345 : %-08.6u.\r\n", 12345); 60 | SEGGER_RTT_printf(0, "printf Test: %%-0u, 12345 : %-0u.\r\n", 12345); 61 | 62 | SEGGER_RTT_printf(0, "printf Test: %%u, -12345 : %u.\r\n", -12345); 63 | SEGGER_RTT_printf(0, "printf Test: %%+u, -12345 : %+u.\r\n", -12345); 64 | SEGGER_RTT_printf(0, "printf Test: %%.3u, -12345 : %.3u.\r\n", -12345); 65 | SEGGER_RTT_printf(0, "printf Test: %%.6u, -12345 : %.6u.\r\n", -12345); 66 | SEGGER_RTT_printf(0, "printf Test: %%6.3u, -12345 : %6.3u.\r\n", -12345); 67 | SEGGER_RTT_printf(0, "printf Test: %%8.6u, -12345 : %8.6u.\r\n", -12345); 68 | SEGGER_RTT_printf(0, "printf Test: %%08u, -12345 : %08u.\r\n", -12345); 69 | SEGGER_RTT_printf(0, "printf Test: %%08.6u, -12345 : %08.6u.\r\n", -12345); 70 | SEGGER_RTT_printf(0, "printf Test: %%0u, -12345 : %0u.\r\n", -12345); 71 | SEGGER_RTT_printf(0, "printf Test: %%-.6u, -12345 : %-.6u.\r\n", -12345); 72 | SEGGER_RTT_printf(0, "printf Test: %%-6.3u, -12345 : %-6.3u.\r\n", -12345); 73 | SEGGER_RTT_printf(0, "printf Test: %%-8.6u, -12345 : %-8.6u.\r\n", -12345); 74 | SEGGER_RTT_printf(0, "printf Test: %%-08u, -12345 : %-08u.\r\n", -12345); 75 | SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345); 76 | SEGGER_RTT_printf(0, "printf Test: %%-0u, -12345 : %-0u.\r\n", -12345); 77 | 78 | SEGGER_RTT_printf(0, "printf Test: %%d, -12345 : %d.\r\n", -12345); 79 | SEGGER_RTT_printf(0, "printf Test: %%+d, -12345 : %+d.\r\n", -12345); 80 | SEGGER_RTT_printf(0, "printf Test: %%.3d, -12345 : %.3d.\r\n", -12345); 81 | SEGGER_RTT_printf(0, "printf Test: %%.6d, -12345 : %.6d.\r\n", -12345); 82 | SEGGER_RTT_printf(0, "printf Test: %%6.3d, -12345 : %6.3d.\r\n", -12345); 83 | SEGGER_RTT_printf(0, "printf Test: %%8.6d, -12345 : %8.6d.\r\n", -12345); 84 | SEGGER_RTT_printf(0, "printf Test: %%08d, -12345 : %08d.\r\n", -12345); 85 | SEGGER_RTT_printf(0, "printf Test: %%08.6d, -12345 : %08.6d.\r\n", -12345); 86 | SEGGER_RTT_printf(0, "printf Test: %%0d, -12345 : %0d.\r\n", -12345); 87 | SEGGER_RTT_printf(0, "printf Test: %%-.6d, -12345 : %-.6d.\r\n", -12345); 88 | SEGGER_RTT_printf(0, "printf Test: %%-6.3d, -12345 : %-6.3d.\r\n", -12345); 89 | SEGGER_RTT_printf(0, "printf Test: %%-8.6d, -12345 : %-8.6d.\r\n", -12345); 90 | SEGGER_RTT_printf(0, "printf Test: %%-08d, -12345 : %-08d.\r\n", -12345); 91 | SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345); 92 | SEGGER_RTT_printf(0, "printf Test: %%-0d, -12345 : %-0d.\r\n", -12345); 93 | 94 | SEGGER_RTT_printf(0, "printf Test: %%x, 0x1234ABC : %x.\r\n", 0x1234ABC); 95 | SEGGER_RTT_printf(0, "printf Test: %%+x, 0x1234ABC : %+x.\r\n", 0x1234ABC); 96 | SEGGER_RTT_printf(0, "printf Test: %%.3x, 0x1234ABC : %.3x.\r\n", 0x1234ABC); 97 | SEGGER_RTT_printf(0, "printf Test: %%.6x, 0x1234ABC : %.6x.\r\n", 0x1234ABC); 98 | SEGGER_RTT_printf(0, "printf Test: %%6.3x, 0x1234ABC : %6.3x.\r\n", 0x1234ABC); 99 | SEGGER_RTT_printf(0, "printf Test: %%8.6x, 0x1234ABC : %8.6x.\r\n", 0x1234ABC); 100 | SEGGER_RTT_printf(0, "printf Test: %%08x, 0x1234ABC : %08x.\r\n", 0x1234ABC); 101 | SEGGER_RTT_printf(0, "printf Test: %%08.6x, 0x1234ABC : %08.6x.\r\n", 0x1234ABC); 102 | SEGGER_RTT_printf(0, "printf Test: %%0x, 0x1234ABC : %0x.\r\n", 0x1234ABC); 103 | SEGGER_RTT_printf(0, "printf Test: %%-.6x, 0x1234ABC : %-.6x.\r\n", 0x1234ABC); 104 | SEGGER_RTT_printf(0, "printf Test: %%-6.3x, 0x1234ABC : %-6.3x.\r\n", 0x1234ABC); 105 | SEGGER_RTT_printf(0, "printf Test: %%-8.6x, 0x1234ABC : %-8.6x.\r\n", 0x1234ABC); 106 | SEGGER_RTT_printf(0, "printf Test: %%-08x, 0x1234ABC : %-08x.\r\n", 0x1234ABC); 107 | SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC); 108 | SEGGER_RTT_printf(0, "printf Test: %%-0x, 0x1234ABC : %-0x.\r\n", 0x1234ABC); 109 | 110 | SEGGER_RTT_printf(0, "printf Test: %%p, &_Cnt : %p.\r\n", &_Cnt); 111 | 112 | SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n"); 113 | do { 114 | _Cnt++; 115 | } while (1); 116 | } 117 | 118 | /*************************** End of file ****************************/ 119 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Examples/Main_RTT_SpeedTestApp.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | 12 | --------- END-OF-HEADER -------------------------------------------- 13 | File : Main_RTT_SpeedTestApp.c 14 | Purpose : Sample program for measuring RTT performance. 15 | */ 16 | 17 | #include "RTOS.h" 18 | #include "BSP.h" 19 | 20 | #include "SEGGER_RTT.h" 21 | #include 22 | 23 | OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */ 24 | OS_TASK TCBHP, TCBLP; /* Task-control-blocks */ 25 | 26 | static void HPTask(void) { 27 | while (1) { 28 | // 29 | // Measure time needed for RTT output 30 | // Perform dummy write with 0 characters, so we know the overhead of toggling LEDs and RTT in general 31 | // 32 | // Set BP here. Then start sampling on scope 33 | BSP_ClrLED(0); 34 | SEGGER_RTT_Write(0, 0, 0); 35 | BSP_SetLED(0); 36 | BSP_ClrLED(0); 37 | SEGGER_RTT_Write(0, "01234567890123456789012345678901234567890123456789012345678901234567890123456789\r\n", 82); 38 | BSP_SetLED(0); 39 | // Set BP here. Then stop sampling on scope 40 | OS_Delay(200); 41 | } 42 | } 43 | 44 | static void LPTask(void) { 45 | while (1) { 46 | BSP_ToggleLED(1); 47 | OS_Delay (500); 48 | } 49 | } 50 | 51 | /********************************************************************* 52 | * 53 | * main 54 | * 55 | *********************************************************************/ 56 | 57 | int main(void) { 58 | OS_IncDI(); /* Initially disable interrupts */ 59 | OS_InitKern(); /* Initialize OS */ 60 | OS_InitHW(); /* Initialize Hardware for OS */ 61 | BSP_Init(); /* Initialize LED ports */ 62 | BSP_SetLED(0); 63 | /* You need to create at least one task before calling OS_Start() */ 64 | OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP); 65 | OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP); 66 | OS_Start(); /* Start multitasking */ 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/License.txt: -------------------------------------------------------------------------------- 1 | Important - Read carefully: 2 | 3 | SEGGER RTT - Real Time Transfer for embedded targets 4 | 5 | All rights reserved. 6 | 7 | SEGGER strongly recommends to not make any changes 8 | to or modify the source code of this software in order to stay 9 | compatible with the RTT protocol and J-Link. 10 | 11 | Redistribution and use in source and binary forms, with or 12 | without modification, are permitted provided that the following 13 | conditions are met: 14 | 15 | o Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | o Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the following 20 | disclaimer in the documentation and/or other materials provided 21 | with the distribution. 22 | 23 | o Neither the name of SEGGER Microcontroller GmbH 24 | nor the names of its contributors may be used to endorse or 25 | promote products derived from this software without specific 26 | prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 29 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 30 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR 33 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 35 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 36 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 39 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 40 | DAMAGE. 41 | 42 | 43 | (c) 2014 - 2016 SEGGER Microcontroller GmbH 44 | www.segger.com 45 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/README.txt: -------------------------------------------------------------------------------- 1 | README.txt for the SEGGER RTT Implementation Pack. 2 | 3 | Included files: 4 | =============== 5 | Root Directory 6 | - Examples 7 | - Main_RTT_InputEchoApp.c - Sample application which echoes input on Channel 0. 8 | - Main_RTT_MenuApp.c - Sample application to demonstrate RTT bi-directional functionality. 9 | - Main_RTT_PrintfTest.c - Sample application to test RTT small printf implementation. 10 | - Main_RTT_SpeedTestApp.c - Sample application for measuring RTT performance. embOS needed. 11 | - RTT 12 | - SEGGER_RTT.c - The RTT implementation. 13 | - SEGGER_RTT.h - Header for RTT implementation. 14 | - SEGGER_RTT_Conf.h - Pre-processor configuration for the RTT implementation. 15 | - SEGGER_RTT_Printf.c - Simple implementation of printf to write formatted strings via RTT. 16 | - Syscalls 17 | - RTT_Syscalls_GCC.c - Low-level syscalls to retarget printf() to RTT with GCC / Newlib. 18 | - RTT_Syscalls_IAR.c - Low-level syscalls to retarget printf() to RTT with IAR compiler. 19 | - RTT_Syscalls_KEIL.c - Low-level syscalls to retarget printf() to RTT with KEIL/uVision compiler. 20 | - RTT_Syscalls_SES.c - Low-level syscalls to retarget printf() to RTT with SEGGER Embedded Studio. 21 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/RTT/SEGGER_RTT.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : SEGGER_RTT.h 56 | Purpose : Implementation of SEGGER real-time transfer which allows 57 | real-time communication on targets which support debugger 58 | memory accesses while the CPU is running. 59 | Revision: $Rev: 16714 $ 60 | ---------------------------------------------------------------------- 61 | */ 62 | 63 | #ifndef SEGGER_RTT_H 64 | #define SEGGER_RTT_H 65 | 66 | #include "SEGGER_RTT_Conf.h" 67 | 68 | 69 | 70 | /********************************************************************* 71 | * 72 | * Defines, defaults 73 | * 74 | ********************************************************************** 75 | */ 76 | #ifndef RTT_USE_ASM 77 | #if (defined __SES_ARM) // SEGGER Embedded Studio 78 | #define _CC_HAS_RTT_ASM_SUPPORT 1 79 | #elif (defined __CROSSWORKS_ARM) // Rowley Crossworks 80 | #define _CC_HAS_RTT_ASM_SUPPORT 1 81 | #elif (defined __GNUC__) // GCC 82 | #define _CC_HAS_RTT_ASM_SUPPORT 1 83 | #elif (defined __clang__) // Clang compiler 84 | #define _CC_HAS_RTT_ASM_SUPPORT 1 85 | #elif (defined __IASMARM__) // IAR assembler 86 | #define _CC_HAS_RTT_ASM_SUPPORT 1 87 | #elif (defined __ICCARM__) // IAR compiler 88 | #define _CC_HAS_RTT_ASM_SUPPORT 1 89 | #else 90 | #define _CC_HAS_RTT_ASM_SUPPORT 0 91 | #endif 92 | #if (defined __ARM_ARCH_7M__) // Cortex-M3/4 93 | #define _CORE_HAS_RTT_ASM_SUPPORT 1 94 | #elif (defined __ARM_ARCH_7EM__) // Cortex-M7 95 | #define _CORE_HAS_RTT_ASM_SUPPORT 1 96 | #elif (defined __ARM_ARCH_8M_MAIN__) // Cortex-M33 97 | #define _CORE_HAS_RTT_ASM_SUPPORT 1 98 | #elif (defined __ARM7M__) // IAR Cortex-M3/4 99 | #if (__CORE__ == __ARM7M__) 100 | #define _CORE_HAS_RTT_ASM_SUPPORT 1 101 | #else 102 | #define _CORE_HAS_RTT_ASM_SUPPORT 0 103 | #endif 104 | #elif (defined __ARM7EM__) // IAR Cortex-M7 105 | #if (__CORE__ == __ARM7EM__) 106 | #define _CORE_HAS_RTT_ASM_SUPPORT 1 107 | #else 108 | #define _CORE_HAS_RTT_ASM_SUPPORT 0 109 | #endif 110 | #else 111 | #define _CORE_HAS_RTT_ASM_SUPPORT 0 112 | #endif 113 | // 114 | // If IDE and core support the ASM version, enable ASM version by default 115 | // 116 | #if (_CC_HAS_RTT_ASM_SUPPORT && _CORE_HAS_RTT_ASM_SUPPORT) 117 | #define RTT_USE_ASM (1) 118 | #else 119 | #define RTT_USE_ASM (0) 120 | #endif 121 | #endif 122 | 123 | #ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file 124 | #include 125 | #include 126 | 127 | /********************************************************************* 128 | * 129 | * Defines, fixed 130 | * 131 | ********************************************************************** 132 | */ 133 | 134 | /********************************************************************* 135 | * 136 | * Types 137 | * 138 | ********************************************************************** 139 | */ 140 | 141 | // 142 | // Description for a circular buffer (also called "ring buffer") 143 | // which is used as up-buffer (T->H) 144 | // 145 | typedef struct { 146 | const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4" 147 | char* pBuffer; // Pointer to start of buffer 148 | unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty. 149 | unsigned WrOff; // Position of next item to be written by either target. 150 | volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host. 151 | unsigned Flags; // Contains configuration flags 152 | } SEGGER_RTT_BUFFER_UP; 153 | 154 | // 155 | // Description for a circular buffer (also called "ring buffer") 156 | // which is used as down-buffer (H->T) 157 | // 158 | typedef struct { 159 | const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4" 160 | char* pBuffer; // Pointer to start of buffer 161 | unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty. 162 | volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host. 163 | unsigned RdOff; // Position of next item to be read by target (down-buffer). 164 | unsigned Flags; // Contains configuration flags 165 | } SEGGER_RTT_BUFFER_DOWN; 166 | 167 | // 168 | // RTT control block which describes the number of buffers available 169 | // as well as the configuration for each buffer 170 | // 171 | // 172 | typedef struct { 173 | char acID[16]; // Initialized to "SEGGER RTT" 174 | int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2) 175 | int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2) 176 | SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host 177 | SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target 178 | } SEGGER_RTT_CB; 179 | 180 | /********************************************************************* 181 | * 182 | * Global data 183 | * 184 | ********************************************************************** 185 | */ 186 | extern SEGGER_RTT_CB _SEGGER_RTT; 187 | 188 | /********************************************************************* 189 | * 190 | * RTT API functions 191 | * 192 | ********************************************************************** 193 | */ 194 | #ifdef __cplusplus 195 | extern "C" { 196 | #endif 197 | int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); 198 | int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); 199 | int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); 200 | int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags); 201 | int SEGGER_RTT_GetKey (void); 202 | unsigned SEGGER_RTT_HasData (unsigned BufferIndex); 203 | int SEGGER_RTT_HasKey (void); 204 | unsigned SEGGER_RTT_HasDataUp (unsigned BufferIndex); 205 | void SEGGER_RTT_Init (void); 206 | unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize); 207 | unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize); 208 | int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName); 209 | int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName); 210 | int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags); 211 | int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags); 212 | int SEGGER_RTT_WaitKey (void); 213 | unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); 214 | unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); 215 | unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); 216 | unsigned SEGGER_RTT_ASM_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); 217 | unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s); 218 | void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes); 219 | unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c); 220 | unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c); 221 | unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c); 222 | // 223 | // Function macro for performance optimization 224 | // 225 | #define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff) 226 | 227 | #if RTT_USE_ASM 228 | #define SEGGER_RTT_WriteSkipNoLock SEGGER_RTT_ASM_WriteSkipNoLock 229 | #endif 230 | 231 | /********************************************************************* 232 | * 233 | * RTT "Terminal" API functions 234 | * 235 | ********************************************************************** 236 | */ 237 | int SEGGER_RTT_SetTerminal (unsigned char TerminalId); 238 | int SEGGER_RTT_TerminalOut (unsigned char TerminalId, const char* s); 239 | 240 | /********************************************************************* 241 | * 242 | * RTT printf functions (require SEGGER_RTT_printf.c) 243 | * 244 | ********************************************************************** 245 | */ 246 | int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...); 247 | int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList); 248 | 249 | #ifdef __cplusplus 250 | } 251 | #endif 252 | 253 | #endif // ifndef(SEGGER_RTT_ASM) 254 | 255 | /********************************************************************* 256 | * 257 | * Defines 258 | * 259 | ********************************************************************** 260 | */ 261 | 262 | // 263 | // Operating modes. Define behavior if buffer is full (not enough space for entire message) 264 | // 265 | #define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default) 266 | #define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits. 267 | #define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer. 268 | #define SEGGER_RTT_MODE_MASK (3) 269 | 270 | // 271 | // Control sequences, based on ANSI. 272 | // Can be used to control color, and clear the screen 273 | // 274 | #define RTT_CTRL_RESET "\x1B[0m" // Reset to default colors 275 | #define RTT_CTRL_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left 276 | 277 | #define RTT_CTRL_TEXT_BLACK "\x1B[2;30m" 278 | #define RTT_CTRL_TEXT_RED "\x1B[2;31m" 279 | #define RTT_CTRL_TEXT_GREEN "\x1B[2;32m" 280 | #define RTT_CTRL_TEXT_YELLOW "\x1B[2;33m" 281 | #define RTT_CTRL_TEXT_BLUE "\x1B[2;34m" 282 | #define RTT_CTRL_TEXT_MAGENTA "\x1B[2;35m" 283 | #define RTT_CTRL_TEXT_CYAN "\x1B[2;36m" 284 | #define RTT_CTRL_TEXT_WHITE "\x1B[2;37m" 285 | 286 | #define RTT_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m" 287 | #define RTT_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m" 288 | #define RTT_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m" 289 | #define RTT_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m" 290 | #define RTT_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m" 291 | #define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m" 292 | #define RTT_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m" 293 | #define RTT_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m" 294 | 295 | #define RTT_CTRL_BG_BLACK "\x1B[24;40m" 296 | #define RTT_CTRL_BG_RED "\x1B[24;41m" 297 | #define RTT_CTRL_BG_GREEN "\x1B[24;42m" 298 | #define RTT_CTRL_BG_YELLOW "\x1B[24;43m" 299 | #define RTT_CTRL_BG_BLUE "\x1B[24;44m" 300 | #define RTT_CTRL_BG_MAGENTA "\x1B[24;45m" 301 | #define RTT_CTRL_BG_CYAN "\x1B[24;46m" 302 | #define RTT_CTRL_BG_WHITE "\x1B[24;47m" 303 | 304 | #define RTT_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m" 305 | #define RTT_CTRL_BG_BRIGHT_RED "\x1B[4;41m" 306 | #define RTT_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m" 307 | #define RTT_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m" 308 | #define RTT_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m" 309 | #define RTT_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m" 310 | #define RTT_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m" 311 | #define RTT_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m" 312 | 313 | 314 | #endif 315 | 316 | /*************************** End of file ****************************/ 317 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/RTT/SEGGER_RTT_ASM_ARMv7M.S: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * (c) SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | * www.segger.com * 5 | ********************************************************************** 6 | 7 | -------------------------- END-OF-HEADER ----------------------------- 8 | 9 | File : SEGGER_RTT_ASM_ARMv7M.S 10 | Purpose : Assembler implementation of RTT functions for ARMv7M 11 | 12 | Additional information: 13 | This module is written to be assembler-independent and works with 14 | GCC and clang (Embedded Studio) and IAR. 15 | */ 16 | 17 | #define SEGGER_RTT_ASM // Used to control processed input from header file 18 | #include "SEGGER_RTT.h" 19 | 20 | /********************************************************************* 21 | * 22 | * Defines, fixed 23 | * 24 | ********************************************************************** 25 | */ 26 | #define _CCIAR 0 27 | #define _CCCLANG 1 28 | 29 | #if (defined __SES_ARM) || (defined __GNUC__) || (defined __clang__) 30 | #define _CC_TYPE _CCCLANG 31 | #define _PUB_SYM .global 32 | #define _EXT_SYM .extern 33 | #define _END .end 34 | #define _WEAK .weak 35 | #define _THUMB_FUNC .thumb_func 36 | #define _THUMB_CODE .code 16 37 | #define _WORD .word 38 | #define _SECTION(Sect, Type, AlignExp) .section Sect ##, "ax" 39 | #define _ALIGN(Exp) .align Exp 40 | #define _PLACE_LITS .ltorg 41 | #define _DATA_SECT_START 42 | #define _C_STARTUP _start 43 | #define _STACK_END __stack_end__ 44 | #define _RAMFUNC 45 | // 46 | // .text => Link to flash 47 | // .fast => Link to RAM 48 | // OtherSect => Usually link to RAM 49 | // Alignment is 2^x 50 | // 51 | #elif defined (__IASMARM__) 52 | #define _CC_TYPE _CCIAR 53 | #define _PUB_SYM PUBLIC 54 | #define _EXT_SYM EXTERN 55 | #define _END END 56 | #define _WEAK _WEAK 57 | #define _THUMB_FUNC 58 | #define _THUMB_CODE THUMB 59 | #define _WORD DCD 60 | #define _SECTION(Sect, Type, AlignExp) SECTION Sect ## : ## Type ## :REORDER:NOROOT ## (AlignExp) 61 | #define _ALIGN(Exp) alignrom Exp 62 | #define _PLACE_LITS 63 | #define _DATA_SECT_START DATA 64 | #define _C_STARTUP __iar_program_start 65 | #define _STACK_END sfe(CSTACK) 66 | #define _RAMFUNC SECTION_TYPE SHT_PROGBITS, SHF_WRITE | SHF_EXECINSTR 67 | // 68 | // .text => Link to flash 69 | // .textrw => Link to RAM 70 | // OtherSect => Usually link to RAM 71 | // NOROOT => Allows linker to throw away the function, if not referenced 72 | // Alignment is 2^x 73 | // 74 | #endif 75 | 76 | #if (_CC_TYPE == _CCIAR) 77 | NAME SEGGER_RTT_ASM_ARMv7M 78 | #else 79 | .syntax unified 80 | #endif 81 | 82 | #if defined (RTT_USE_ASM) && (RTT_USE_ASM == 1) 83 | #define SHT_PROGBITS 0x1 84 | 85 | /********************************************************************* 86 | * 87 | * Public / external symbols 88 | * 89 | ********************************************************************** 90 | */ 91 | 92 | _EXT_SYM __aeabi_memcpy 93 | _EXT_SYM __aeabi_memcpy4 94 | _EXT_SYM _SEGGER_RTT 95 | 96 | _PUB_SYM SEGGER_RTT_ASM_WriteSkipNoLock 97 | 98 | /********************************************************************* 99 | * 100 | * SEGGER_RTT_WriteSkipNoLock 101 | * 102 | * Function description 103 | * Stores a specified number of characters in SEGGER RTT 104 | * control block which is then read by the host. 105 | * SEGGER_RTT_WriteSkipNoLock does not lock the application and 106 | * skips all data, if the data does not fit into the buffer. 107 | * 108 | * Parameters 109 | * BufferIndex Index of "Up"-buffer to be used (e.g. 0 for "Terminal"). 110 | * pBuffer Pointer to character array. Does not need to point to a \0 terminated string. 111 | * NumBytes Number of bytes to be stored in the SEGGER RTT control block. 112 | * MUST be > 0!!! 113 | * This is done for performance reasons, so no initial check has do be done. 114 | * 115 | * Return value 116 | * 1: Data has been copied 117 | * 0: No space, data has not been copied 118 | * 119 | * Notes 120 | * (1) If there is not enough space in the "Up"-buffer, all data is dropped. 121 | * (2) For performance reasons this function does not call Init() 122 | * and may only be called after RTT has been initialized. 123 | * Either by calling SEGGER_RTT_Init() or calling another RTT API function first. 124 | */ 125 | _SECTION(.text, CODE, 2) 126 | _ALIGN(2) 127 | _THUMB_FUNC 128 | SEGGER_RTT_ASM_WriteSkipNoLock: // unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pData, unsigned NumBytes) { 129 | // 130 | // Cases: 131 | // 1) RdOff <= WrOff => Space until wrap-around is sufficient 132 | // 2) RdOff <= WrOff => Space after wrap-around needed (copy in 2 chunks) 133 | // 3) RdOff < WrOff => No space in buf 134 | // 4) RdOff > WrOff => Space is sufficient 135 | // 5) RdOff > WrOff => No space in buf 136 | // 137 | // 1) is the most common case for large buffers and assuming that J-Link reads the data fast enough 138 | // 139 | // Register usage: 140 | // R0 Temporary needed as RdOff, register later on 141 | // R1 pData 142 | // R2 143 | // R3 register. Hold free for subroutine calls 144 | // R4 145 | // R5 pRing->pBuffer 146 | // R6 pRing (Points to active struct SEGGER_RTT_BUFFER_DOWN) 147 | // R7 WrOff 148 | // 149 | PUSH {R4-R7} 150 | ADD R3,R0,R0, LSL #+1 151 | LDR.W R0,=_SEGGER_RTT // pRing = &_SEGGER_RTT.aUp[BufferIndex]; 152 | ADD R0,R0,R3, LSL #+3 153 | ADD R6,R0,#+24 154 | LDR R0,[R6, #+16] // RdOff = pRing->RdOff; 155 | LDR R7,[R6, #+12] // WrOff = pRing->WrOff; 156 | LDR R5,[R6, #+4] // pRing->pBuffer 157 | CMP R7,R0 158 | BCC.N _CheckCase4 // if (RdOff <= WrOff) { => Case 1), 2) or 3) 159 | // 160 | // Handling for case 1, later on identical to case 4 161 | // 162 | LDR R3,[R6, #+8] // Avail = pRing->SizeOfBuffer - WrOff - 1u; => Space until wrap-around (assume 1 byte not usable for case that RdOff == 0) 163 | SUBS R4,R3,R7 // (Used in case we jump into case 2 afterwards) 164 | SUBS R3,R4,#+1 // 165 | CMP R3,R2 166 | BCC.N _CheckCase2 // if (Avail >= NumBytes) { => Case 1)? 167 | _Case4: 168 | ADDS R5,R7,R5 // pBuffer += WrOff 169 | ADDS R0,R2,R7 // v = WrOff + NumBytes 170 | // 171 | // 2x unrolling for the copy loop that is used most of the time 172 | // This is a special optimization for small SystemView packets and makes them even faster 173 | // 174 | _ALIGN(2) 175 | _LoopCopyStraight: // memcpy(pRing->pBuffer + WrOff, pData, NumBytes); 176 | LDRB R3,[R1], #+1 177 | STRB R3,[R5], #+1 // *pDest++ = *pSrc++ 178 | SUBS R2,R2,#+1 179 | BEQ _CSDone 180 | LDRB R3,[R1], #+1 181 | STRB R3,[R5], #+1 // *pDest++ = *pSrc++ 182 | SUBS R2,R2,#+1 183 | BNE _LoopCopyStraight 184 | _CSDone: 185 | STR R0,[R6, #+12] // pRing->WrOff = WrOff + NumBytes; 186 | MOVS R0,#+1 187 | POP {R4-R7} 188 | BX LR // Return 1 189 | _CheckCase2: 190 | ADDS R0,R0,R3 // Avail += RdOff; => Space incl. wrap-around 191 | CMP R0,R2 192 | BCC.N _Case3 // if (Avail >= NumBytes) { => Case 2? => If not, we have case 3) (does not fit) 193 | // 194 | // Handling for case 2 195 | // 196 | ADDS R0,R7,R5 // v = pRing->pBuffer + WrOff => Do not change pRing->pBuffer here because 2nd chunk needs org. value 197 | SUBS R2,R2,R4 // NumBytes -= Rem; (Rem = pRing->SizeOfBuffer - WrOff; => Space until end of buffer) 198 | _LoopCopyBeforeWrapAround: // memcpy(pRing->pBuffer + WrOff, pData, Rem); => Copy 1st chunk 199 | LDRB R3,[R1], #+1 200 | STRB R3,[R0], #+1 // *pDest++ = *pSrc++ 201 | SUBS R4,R4,#+1 202 | BNE _LoopCopyBeforeWrapAround 203 | // 204 | // Special case: First check that assumed RdOff == 0 calculated that last element before wrap-around could not be used 205 | // But 2nd check (considering space until wrap-around and until RdOff) revealed that RdOff is not 0, so we can use the last element 206 | // In this case, we may use a copy straight until buffer end anyway without needing to copy 2 chunks 207 | // Therefore, check if 2nd memcpy is necessary at all 208 | // 209 | ADDS R4,R2,#+0 // Save (needed as counter in loop but must be written to after the loop). Also use this inst to update the flags to skip 2nd loop if possible 210 | BEQ.N _No2ChunkNeeded // if (NumBytes) { 211 | _LoopCopyAfterWrapAround: // memcpy(pRing->pBuffer, pData + Rem, NumBytes); 212 | LDRB R3,[R1], #+1 // pData already points to the next src byte due to copy loop increment before this loop 213 | STRB R3,[R5], #+1 // *pDest++ = *pSrc++ 214 | SUBS R2,R2,#+1 215 | BNE _LoopCopyAfterWrapAround 216 | _No2ChunkNeeded: 217 | STR R4,[R6, #+12] // pRing->WrOff = NumBytes; => Must be written after copying data because J-Link may read control block asynchronously while writing into buffer 218 | MOVS R0,#+1 219 | POP {R4-R7} 220 | BX LR // Return 1 221 | _CheckCase4: 222 | SUBS R0,R0,R7 223 | SUBS R0,R0,#+1 // Avail = RdOff - WrOff - 1u; 224 | CMP R0,R2 225 | BCS.N _Case4 // if (Avail >= NumBytes) { => Case 4) == 1) ? => If not, we have case 5) == 3) (does not fit) 226 | _Case3: 227 | MOVS R0,#+0 228 | POP {R4-R7} 229 | BX LR // Return 0 230 | _PLACE_LITS 231 | 232 | #endif // defined (RTT_USE_ASM) && (RTT_USE_ASM == 1) 233 | _END 234 | 235 | /*************************** End of file ****************************/ 236 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/RTT/SEGGER_RTT_Conf.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : SEGGER_RTT_Conf.h 56 | Purpose : Implementation of SEGGER real-time transfer (RTT) which 57 | allows real-time communication on targets which support 58 | debugger memory accesses while the CPU is running. 59 | Revision: $Rev: 15929 $ 60 | 61 | */ 62 | 63 | #ifndef SEGGER_RTT_CONF_H 64 | #define SEGGER_RTT_CONF_H 65 | 66 | #ifdef __IAR_SYSTEMS_ICC__ 67 | #include 68 | #endif 69 | 70 | /********************************************************************* 71 | * 72 | * Defines, configurable 73 | * 74 | ********************************************************************** 75 | */ 76 | 77 | #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3) 78 | #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3) 79 | 80 | #define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k) 81 | #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) 82 | 83 | #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) 84 | 85 | #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0) 86 | 87 | /********************************************************************* 88 | * 89 | * RTT memcpy configuration 90 | * 91 | * memcpy() is good for large amounts of data, 92 | * but the overhead is big for small amounts, which are usually stored via RTT. 93 | * With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead. 94 | * 95 | * SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions. 96 | * This is may be required with memory access restrictions, 97 | * such as on Cortex-A devices with MMU. 98 | */ 99 | #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop 100 | // 101 | // Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets 102 | // 103 | //#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__)) 104 | // #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes)) 105 | //#endif 106 | 107 | // 108 | // Target is not allowed to perform other RTT operations while string still has not been stored completely. 109 | // Otherwise we would probably end up with a mixed string in the buffer. 110 | // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here. 111 | // 112 | // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4. 113 | // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches. 114 | // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly. 115 | // (Higher priority = lower priority number) 116 | // Default value for embOS: 128u 117 | // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 118 | // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC 119 | // or define SEGGER_RTT_LOCK() to completely disable interrupts. 120 | // 121 | 122 | #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20) 123 | 124 | /********************************************************************* 125 | * 126 | * RTT lock configuration for SEGGER Embedded Studio, 127 | * Rowley CrossStudio and GCC 128 | */ 129 | #if (defined(__SES_ARM) || defined(__CROSSWORKS_ARM) || defined(__GNUC__) || defined(__clang__)) && !defined (__CC_ARM) 130 | #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__)) 131 | #define SEGGER_RTT_LOCK() { \ 132 | unsigned int LockState; \ 133 | __asm volatile ("mrs %0, primask \n\t" \ 134 | "movs r1, $1 \n\t" \ 135 | "msr primask, r1 \n\t" \ 136 | : "=r" (LockState) \ 137 | : \ 138 | : "r1" \ 139 | ); 140 | 141 | #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \ 142 | : \ 143 | : "r" (LockState) \ 144 | : \ 145 | ); \ 146 | } 147 | #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)) 148 | #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 149 | #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 150 | #endif 151 | #define SEGGER_RTT_LOCK() { \ 152 | unsigned int LockState; \ 153 | __asm volatile ("mrs %0, basepri \n\t" \ 154 | "mov r1, %1 \n\t" \ 155 | "msr basepri, r1 \n\t" \ 156 | : "=r" (LockState) \ 157 | : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \ 158 | : "r1" \ 159 | ); 160 | 161 | #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \ 162 | : \ 163 | : "r" (LockState) \ 164 | : \ 165 | ); \ 166 | } 167 | 168 | #elif defined(__ARM_ARCH_7A__) 169 | #define SEGGER_RTT_LOCK() { \ 170 | unsigned int LockState; \ 171 | __asm volatile ("mrs r1, CPSR \n\t" \ 172 | "mov %0, r1 \n\t" \ 173 | "orr r1, r1, #0xC0 \n\t" \ 174 | "msr CPSR_c, r1 \n\t" \ 175 | : "=r" (LockState) \ 176 | : \ 177 | : "r1" \ 178 | ); 179 | 180 | #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \ 181 | "mrs r1, CPSR \n\t" \ 182 | "bic r1, r1, #0xC0 \n\t" \ 183 | "and r0, r0, #0xC0 \n\t" \ 184 | "orr r1, r1, r0 \n\t" \ 185 | "msr CPSR_c, r1 \n\t" \ 186 | : \ 187 | : "r" (LockState) \ 188 | : "r0", "r1" \ 189 | ); \ 190 | } 191 | #endif 192 | #endif 193 | 194 | /********************************************************************* 195 | * 196 | * RTT lock configuration for IAR EWARM 197 | */ 198 | #ifdef __ICCARM__ 199 | #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__)) 200 | #define SEGGER_RTT_LOCK() { \ 201 | unsigned int LockState; \ 202 | LockState = __get_PRIMASK(); \ 203 | __set_PRIMASK(1); 204 | 205 | #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \ 206 | } 207 | #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__))) 208 | #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 209 | #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 210 | #endif 211 | #define SEGGER_RTT_LOCK() { \ 212 | unsigned int LockState; \ 213 | LockState = __get_BASEPRI(); \ 214 | __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); 215 | 216 | #define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \ 217 | } 218 | #endif 219 | #endif 220 | 221 | /********************************************************************* 222 | * 223 | * RTT lock configuration for IAR RX 224 | */ 225 | #ifdef __ICCRX__ 226 | #define SEGGER_RTT_LOCK() { \ 227 | unsigned long LockState; \ 228 | LockState = __get_interrupt_state(); \ 229 | __disable_interrupt(); 230 | 231 | #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \ 232 | } 233 | #endif 234 | 235 | /********************************************************************* 236 | * 237 | * RTT lock configuration for IAR RL78 238 | */ 239 | #ifdef __ICCRL78__ 240 | #define SEGGER_RTT_LOCK() { \ 241 | __istate_t LockState; \ 242 | LockState = __get_interrupt_state(); \ 243 | __disable_interrupt(); 244 | 245 | #define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \ 246 | } 247 | #endif 248 | 249 | /********************************************************************* 250 | * 251 | * RTT lock configuration for KEIL ARM 252 | */ 253 | #ifdef __CC_ARM 254 | #if (defined __TARGET_ARCH_6S_M) 255 | #define SEGGER_RTT_LOCK() { \ 256 | unsigned int LockState; \ 257 | register unsigned char PRIMASK __asm( "primask"); \ 258 | LockState = PRIMASK; \ 259 | PRIMASK = 1u; \ 260 | __schedule_barrier(); 261 | 262 | #define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \ 263 | __schedule_barrier(); \ 264 | } 265 | #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) 266 | #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 267 | #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 268 | #endif 269 | #define SEGGER_RTT_LOCK() { \ 270 | unsigned int LockState; \ 271 | register unsigned char BASEPRI __asm( "basepri"); \ 272 | LockState = BASEPRI; \ 273 | BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \ 274 | __schedule_barrier(); 275 | 276 | #define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \ 277 | __schedule_barrier(); \ 278 | } 279 | #endif 280 | #endif 281 | 282 | /********************************************************************* 283 | * 284 | * RTT lock configuration for TI ARM 285 | */ 286 | #ifdef __TI_ARM__ 287 | #if defined (__TI_ARM_V6M0__) 288 | #define SEGGER_RTT_LOCK() { \ 289 | unsigned int LockState; \ 290 | LockState = __get_PRIMASK(); \ 291 | __set_PRIMASK(1); 292 | 293 | #define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \ 294 | } 295 | #elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__)) 296 | #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY 297 | #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) 298 | #endif 299 | #define SEGGER_RTT_LOCK() { \ 300 | unsigned int LockState; \ 301 | LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY); 302 | 303 | #define SEGGER_RTT_UNLOCK() _set_interrupt_priority(LockState); \ 304 | } 305 | #endif 306 | #endif 307 | 308 | /********************************************************************* 309 | * 310 | * RTT lock configuration for CCRX 311 | */ 312 | #ifdef __RX 313 | #define SEGGER_RTT_LOCK() { \ 314 | unsigned long LockState; \ 315 | LockState = get_psw() & 0x010000; \ 316 | clrpsw_i(); 317 | 318 | #define SEGGER_RTT_UNLOCK() set_psw(get_psw() | LockState); \ 319 | } 320 | #endif 321 | 322 | /********************************************************************* 323 | * 324 | * RTT lock configuration fallback 325 | */ 326 | #ifndef SEGGER_RTT_LOCK 327 | #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts) 328 | #endif 329 | 330 | #ifndef SEGGER_RTT_UNLOCK 331 | #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state) 332 | #endif 333 | 334 | #endif 335 | /*************************** End of file ****************************/ 336 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/RTT/SEGGER_RTT_printf.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : SEGGER_RTT_printf.c 56 | Purpose : Replacement for printf to write formatted data via RTT 57 | Revision: $Rev: 12360 $ 58 | ---------------------------------------------------------------------- 59 | */ 60 | #include "SEGGER_RTT.h" 61 | #include "SEGGER_RTT_Conf.h" 62 | 63 | /********************************************************************* 64 | * 65 | * Defines, configurable 66 | * 67 | ********************************************************************** 68 | */ 69 | 70 | #ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE 71 | #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64) 72 | #endif 73 | 74 | #include 75 | #include 76 | 77 | 78 | #define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0) 79 | #define FORMAT_FLAG_PAD_ZERO (1u << 1) 80 | #define FORMAT_FLAG_PRINT_SIGN (1u << 2) 81 | #define FORMAT_FLAG_ALTERNATE (1u << 3) 82 | 83 | /********************************************************************* 84 | * 85 | * Types 86 | * 87 | ********************************************************************** 88 | */ 89 | 90 | typedef struct { 91 | char* pBuffer; 92 | unsigned BufferSize; 93 | unsigned Cnt; 94 | 95 | int ReturnValue; 96 | 97 | unsigned RTTBufferIndex; 98 | } SEGGER_RTT_PRINTF_DESC; 99 | 100 | /********************************************************************* 101 | * 102 | * Function prototypes 103 | * 104 | ********************************************************************** 105 | */ 106 | 107 | /********************************************************************* 108 | * 109 | * Static code 110 | * 111 | ********************************************************************** 112 | */ 113 | /********************************************************************* 114 | * 115 | * _StoreChar 116 | */ 117 | static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) { 118 | unsigned Cnt; 119 | 120 | Cnt = p->Cnt; 121 | if ((Cnt + 1u) <= p->BufferSize) { 122 | *(p->pBuffer + Cnt) = c; 123 | p->Cnt = Cnt + 1u; 124 | p->ReturnValue++; 125 | } 126 | // 127 | // Write part of string, when the buffer is full 128 | // 129 | if (p->Cnt == p->BufferSize) { 130 | if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) { 131 | p->ReturnValue = -1; 132 | } else { 133 | p->Cnt = 0u; 134 | } 135 | } 136 | } 137 | 138 | /********************************************************************* 139 | * 140 | * _PrintUnsigned 141 | */ 142 | static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) { 143 | static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 144 | unsigned Div; 145 | unsigned Digit; 146 | unsigned Number; 147 | unsigned Width; 148 | char c; 149 | 150 | Number = v; 151 | Digit = 1u; 152 | // 153 | // Get actual field width 154 | // 155 | Width = 1u; 156 | while (Number >= Base) { 157 | Number = (Number / Base); 158 | Width++; 159 | } 160 | if (NumDigits > Width) { 161 | Width = NumDigits; 162 | } 163 | // 164 | // Print leading chars if necessary 165 | // 166 | if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) { 167 | if (FieldWidth != 0u) { 168 | if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) { 169 | c = '0'; 170 | } else { 171 | c = ' '; 172 | } 173 | while ((FieldWidth != 0u) && (Width < FieldWidth)) { 174 | FieldWidth--; 175 | _StoreChar(pBufferDesc, c); 176 | if (pBufferDesc->ReturnValue < 0) { 177 | break; 178 | } 179 | } 180 | } 181 | } 182 | if (pBufferDesc->ReturnValue >= 0) { 183 | // 184 | // Compute Digit. 185 | // Loop until Digit has the value of the highest digit required. 186 | // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100. 187 | // 188 | while (1) { 189 | if (NumDigits > 1u) { // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned) 190 | NumDigits--; 191 | } else { 192 | Div = v / Digit; 193 | if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done 194 | break; 195 | } 196 | } 197 | Digit *= Base; 198 | } 199 | // 200 | // Output digits 201 | // 202 | do { 203 | Div = v / Digit; 204 | v -= Div * Digit; 205 | _StoreChar(pBufferDesc, _aV2C[Div]); 206 | if (pBufferDesc->ReturnValue < 0) { 207 | break; 208 | } 209 | Digit /= Base; 210 | } while (Digit); 211 | // 212 | // Print trailing spaces if necessary 213 | // 214 | if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) { 215 | if (FieldWidth != 0u) { 216 | while ((FieldWidth != 0u) && (Width < FieldWidth)) { 217 | FieldWidth--; 218 | _StoreChar(pBufferDesc, ' '); 219 | if (pBufferDesc->ReturnValue < 0) { 220 | break; 221 | } 222 | } 223 | } 224 | } 225 | } 226 | } 227 | 228 | /********************************************************************* 229 | * 230 | * _PrintInt 231 | */ 232 | static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) { 233 | unsigned Width; 234 | int Number; 235 | 236 | Number = (v < 0) ? -v : v; 237 | 238 | // 239 | // Get actual field width 240 | // 241 | Width = 1u; 242 | while (Number >= (int)Base) { 243 | Number = (Number / (int)Base); 244 | Width++; 245 | } 246 | if (NumDigits > Width) { 247 | Width = NumDigits; 248 | } 249 | if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) { 250 | FieldWidth--; 251 | } 252 | 253 | // 254 | // Print leading spaces if necessary 255 | // 256 | if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) { 257 | if (FieldWidth != 0u) { 258 | while ((FieldWidth != 0u) && (Width < FieldWidth)) { 259 | FieldWidth--; 260 | _StoreChar(pBufferDesc, ' '); 261 | if (pBufferDesc->ReturnValue < 0) { 262 | break; 263 | } 264 | } 265 | } 266 | } 267 | // 268 | // Print sign if necessary 269 | // 270 | if (pBufferDesc->ReturnValue >= 0) { 271 | if (v < 0) { 272 | v = -v; 273 | _StoreChar(pBufferDesc, '-'); 274 | } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) { 275 | _StoreChar(pBufferDesc, '+'); 276 | } else { 277 | 278 | } 279 | if (pBufferDesc->ReturnValue >= 0) { 280 | // 281 | // Print leading zeros if necessary 282 | // 283 | if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) { 284 | if (FieldWidth != 0u) { 285 | while ((FieldWidth != 0u) && (Width < FieldWidth)) { 286 | FieldWidth--; 287 | _StoreChar(pBufferDesc, '0'); 288 | if (pBufferDesc->ReturnValue < 0) { 289 | break; 290 | } 291 | } 292 | } 293 | } 294 | if (pBufferDesc->ReturnValue >= 0) { 295 | // 296 | // Print number without sign 297 | // 298 | _PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags); 299 | } 300 | } 301 | } 302 | } 303 | 304 | /********************************************************************* 305 | * 306 | * Public code 307 | * 308 | ********************************************************************** 309 | */ 310 | /********************************************************************* 311 | * 312 | * SEGGER_RTT_vprintf 313 | * 314 | * Function description 315 | * Stores a formatted string in SEGGER RTT control block. 316 | * This data is read by the host. 317 | * 318 | * Parameters 319 | * BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal") 320 | * sFormat Pointer to format string 321 | * pParamList Pointer to the list of arguments for the format string 322 | * 323 | * Return values 324 | * >= 0: Number of bytes which have been stored in the "Up"-buffer. 325 | * < 0: Error 326 | */ 327 | int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) { 328 | char c; 329 | SEGGER_RTT_PRINTF_DESC BufferDesc; 330 | int v; 331 | unsigned NumDigits; 332 | unsigned FormatFlags; 333 | unsigned FieldWidth; 334 | char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE]; 335 | 336 | BufferDesc.pBuffer = acBuffer; 337 | BufferDesc.BufferSize = SEGGER_RTT_PRINTF_BUFFER_SIZE; 338 | BufferDesc.Cnt = 0u; 339 | BufferDesc.RTTBufferIndex = BufferIndex; 340 | BufferDesc.ReturnValue = 0; 341 | 342 | do { 343 | c = *sFormat; 344 | sFormat++; 345 | if (c == 0u) { 346 | break; 347 | } 348 | if (c == '%') { 349 | // 350 | // Filter out flags 351 | // 352 | FormatFlags = 0u; 353 | v = 1; 354 | do { 355 | c = *sFormat; 356 | switch (c) { 357 | case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break; 358 | case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break; 359 | case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break; 360 | case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break; 361 | default: v = 0; break; 362 | } 363 | } while (v); 364 | // 365 | // filter out field with 366 | // 367 | FieldWidth = 0u; 368 | do { 369 | c = *sFormat; 370 | if ((c < '0') || (c > '9')) { 371 | break; 372 | } 373 | sFormat++; 374 | FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0'); 375 | } while (1); 376 | 377 | // 378 | // Filter out precision (number of digits to display) 379 | // 380 | NumDigits = 0u; 381 | c = *sFormat; 382 | if (c == '.') { 383 | sFormat++; 384 | do { 385 | c = *sFormat; 386 | if ((c < '0') || (c > '9')) { 387 | break; 388 | } 389 | sFormat++; 390 | NumDigits = NumDigits * 10u + ((unsigned)c - '0'); 391 | } while (1); 392 | } 393 | // 394 | // Filter out length modifier 395 | // 396 | c = *sFormat; 397 | do { 398 | if ((c == 'l') || (c == 'h')) { 399 | sFormat++; 400 | c = *sFormat; 401 | } else { 402 | break; 403 | } 404 | } while (1); 405 | // 406 | // Handle specifiers 407 | // 408 | switch (c) { 409 | case 'c': { 410 | char c0; 411 | v = va_arg(*pParamList, int); 412 | c0 = (char)v; 413 | _StoreChar(&BufferDesc, c0); 414 | break; 415 | } 416 | case 'd': 417 | v = va_arg(*pParamList, int); 418 | _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags); 419 | break; 420 | case 'u': 421 | v = va_arg(*pParamList, int); 422 | _PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags); 423 | break; 424 | case 'x': 425 | case 'X': 426 | v = va_arg(*pParamList, int); 427 | _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags); 428 | break; 429 | case 's': 430 | { 431 | const char * s = va_arg(*pParamList, const char *); 432 | do { 433 | c = *s; 434 | s++; 435 | if (c == '\0') { 436 | break; 437 | } 438 | _StoreChar(&BufferDesc, c); 439 | } while (BufferDesc.ReturnValue >= 0); 440 | } 441 | break; 442 | case 'p': 443 | v = va_arg(*pParamList, int); 444 | _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u); 445 | break; 446 | case '%': 447 | _StoreChar(&BufferDesc, '%'); 448 | break; 449 | default: 450 | break; 451 | } 452 | sFormat++; 453 | } else { 454 | _StoreChar(&BufferDesc, c); 455 | } 456 | } while (BufferDesc.ReturnValue >= 0); 457 | 458 | if (BufferDesc.ReturnValue > 0) { 459 | // 460 | // Write remaining data, if any 461 | // 462 | if (BufferDesc.Cnt != 0u) { 463 | SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt); 464 | } 465 | BufferDesc.ReturnValue += (int)BufferDesc.Cnt; 466 | } 467 | return BufferDesc.ReturnValue; 468 | } 469 | 470 | /********************************************************************* 471 | * 472 | * SEGGER_RTT_printf 473 | * 474 | * Function description 475 | * Stores a formatted string in SEGGER RTT control block. 476 | * This data is read by the host. 477 | * 478 | * Parameters 479 | * BufferIndex Index of "Up"-buffer to be used. (e.g. 0 for "Terminal") 480 | * sFormat Pointer to format string, followed by the arguments for conversion 481 | * 482 | * Return values 483 | * >= 0: Number of bytes which have been stored in the "Up"-buffer. 484 | * < 0: Error 485 | * 486 | * Notes 487 | * (1) Conversion specifications have following syntax: 488 | * %[flags][FieldWidth][.Precision]ConversionSpecifier 489 | * (2) Supported flags: 490 | * -: Left justify within the field width 491 | * +: Always print sign extension for signed conversions 492 | * 0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision 493 | * Supported conversion specifiers: 494 | * c: Print the argument as one char 495 | * d: Print the argument as a signed integer 496 | * u: Print the argument as an unsigned integer 497 | * x: Print the argument as an hexadecimal integer 498 | * s: Print the string pointed to by the argument 499 | * p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.) 500 | */ 501 | int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) { 502 | int r; 503 | va_list ParamList; 504 | 505 | va_start(ParamList, sFormat); 506 | r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList); 507 | va_end(ParamList); 508 | return r; 509 | } 510 | /*************************** End of file ****************************/ 511 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Syscalls/SEGGER_RTT_Syscalls_GCC.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : SEGGER_RTT_Syscalls_GCC.c 56 | Purpose : Low-level functions for using printf() via RTT in GCC. 57 | To use RTT for printf output, include this file in your 58 | application. 59 | Revision: $Rev: 16265 $ 60 | ---------------------------------------------------------------------- 61 | */ 62 | #if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM) 63 | 64 | #include // required for _write_r 65 | #include "SEGGER_RTT.h" 66 | 67 | 68 | /********************************************************************* 69 | * 70 | * Types 71 | * 72 | ********************************************************************** 73 | */ 74 | // 75 | // If necessary define the _reent struct 76 | // to match the one passed by the used standard library. 77 | // 78 | struct _reent; 79 | 80 | /********************************************************************* 81 | * 82 | * Function prototypes 83 | * 84 | ********************************************************************** 85 | */ 86 | int _write(int file, char *ptr, int len); 87 | int _write_r(struct _reent *r, int file, const void *ptr, int len); 88 | 89 | /********************************************************************* 90 | * 91 | * Global functions 92 | * 93 | ********************************************************************** 94 | */ 95 | 96 | /********************************************************************* 97 | * 98 | * _write() 99 | * 100 | * Function description 101 | * Low-level write function. 102 | * libc subroutines will use this system routine for output to all files, 103 | * including stdout. 104 | * Write data via RTT. 105 | */ 106 | int _write(int file, char *ptr, int len) { 107 | (void) file; /* Not used, avoid warning */ 108 | SEGGER_RTT_Write(0, ptr, len); 109 | return len; 110 | } 111 | 112 | /********************************************************************* 113 | * 114 | * _write_r() 115 | * 116 | * Function description 117 | * Low-level reentrant write function. 118 | * libc subroutines will use this system routine for output to all files, 119 | * including stdout. 120 | * Write data via RTT. 121 | */ 122 | int _write_r(struct _reent *r, int file, const void *ptr, int len) { 123 | (void) file; /* Not used, avoid warning */ 124 | (void) r; /* Not used, avoid warning */ 125 | SEGGER_RTT_Write(0, ptr, len); 126 | return len; 127 | } 128 | 129 | #endif 130 | /****** End Of File *************************************************/ 131 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Syscalls/SEGGER_RTT_Syscalls_IAR.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : SEGGER_RTT_Syscalls_IAR.c 56 | Purpose : Low-level functions for using printf() via RTT in IAR. 57 | To use RTT for printf output, include this file in your 58 | application and set the Library Configuration to Normal. 59 | Revision: $Rev: 16282 $ 60 | ---------------------------------------------------------------------- 61 | */ 62 | #ifdef __IAR_SYSTEMS_ICC__ 63 | 64 | // 65 | // Since IAR EWARM V8 and EWRX V4, yfuns.h is considered as deprecated and LowLevelIOInterface.h 66 | // shall be used instead. To not break any compatibility with older compiler versions, we have a 67 | // version check in here. 68 | // 69 | #if ((defined __ICCARM__) && (__VER__ >= 8000000)) || ((defined __ICCRX__) && (__VER__ >= 400)) 70 | #include 71 | #else 72 | #include 73 | #endif 74 | 75 | #include "SEGGER_RTT.h" 76 | #pragma module_name = "?__write" 77 | 78 | /********************************************************************* 79 | * 80 | * Function prototypes 81 | * 82 | ********************************************************************** 83 | */ 84 | size_t __write(int handle, const unsigned char * buffer, size_t size); 85 | 86 | /********************************************************************* 87 | * 88 | * Global functions 89 | * 90 | ********************************************************************** 91 | */ 92 | /********************************************************************* 93 | * 94 | * __write() 95 | * 96 | * Function description 97 | * Low-level write function. 98 | * Standard library subroutines will use this system routine 99 | * for output to all files, including stdout. 100 | * Write data via RTT. 101 | */ 102 | size_t __write(int handle, const unsigned char * buffer, size_t size) { 103 | (void) handle; /* Not used, avoid warning */ 104 | SEGGER_RTT_Write(0, (const char*)buffer, size); 105 | return size; 106 | } 107 | 108 | /********************************************************************* 109 | * 110 | * __write_buffered() 111 | * 112 | * Function description 113 | * Low-level write function. 114 | * Standard library subroutines will use this system routine 115 | * for output to all files, including stdout. 116 | * Write data via RTT. 117 | */ 118 | size_t __write_buffered(int handle, const unsigned char * buffer, size_t size) { 119 | (void) handle; /* Not used, avoid warning */ 120 | SEGGER_RTT_Write(0, (const char*)buffer, size); 121 | return size; 122 | } 123 | 124 | #endif 125 | /****** End Of File *************************************************/ 126 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Syscalls/SEGGER_RTT_Syscalls_KEIL.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : RTT_Syscalls_KEIL.c 56 | Purpose : Retargeting module for KEIL MDK-CM3. 57 | Low-level functions for using printf() via RTT 58 | Revision: $Rev: 16265 $ 59 | ---------------------------------------------------------------------- 60 | */ 61 | #ifdef __CC_ARM 62 | 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | #include "SEGGER_RTT.h" 70 | /********************************************************************* 71 | * 72 | * #pragmas 73 | * 74 | ********************************************************************** 75 | */ 76 | #pragma import(__use_no_semihosting) 77 | 78 | #ifdef _MICROLIB 79 | #pragma import(__use_full_stdio) 80 | #endif 81 | 82 | /********************************************************************* 83 | * 84 | * Defines non-configurable 85 | * 86 | ********************************************************************** 87 | */ 88 | 89 | /* Standard IO device handles - arbitrary, but any real file system handles must be 90 | less than 0x8000. */ 91 | #define STDIN 0x8001 // Standard Input Stream 92 | #define STDOUT 0x8002 // Standard Output Stream 93 | #define STDERR 0x8003 // Standard Error Stream 94 | 95 | /********************************************************************* 96 | * 97 | * Public const 98 | * 99 | ********************************************************************** 100 | */ 101 | //const char __stdin_name[] = "STDIN"; 102 | const char __stdout_name[] = "STDOUT"; 103 | const char __stderr_name[] = "STDERR"; 104 | 105 | /********************************************************************* 106 | * 107 | * Public code 108 | * 109 | ********************************************************************** 110 | */ 111 | 112 | /********************************************************************* 113 | * 114 | * _ttywrch 115 | * 116 | * Function description: 117 | * Outputs a character to the console 118 | * 119 | * Parameters: 120 | * c - character to output 121 | * 122 | */ 123 | void _ttywrch(int c) { 124 | fputc(c, stdout); // stdout 125 | fflush(stdout); 126 | } 127 | 128 | /********************************************************************* 129 | * 130 | * _sys_open 131 | * 132 | * Function description: 133 | * Opens the device/file in order to do read/write operations 134 | * 135 | * Parameters: 136 | * sName - sName of the device/file to open 137 | * OpenMode - This parameter is currently ignored 138 | * 139 | * Return value: 140 | * != 0 - Handle to the object to open, otherwise 141 | * == 0 -"device" is not handled by this module 142 | * 143 | */ 144 | FILEHANDLE _sys_open(const char * sName, int OpenMode) { 145 | (void)OpenMode; 146 | // Register standard Input Output devices. 147 | if (strcmp(sName, __stdout_name) == 0) { 148 | return (STDOUT); 149 | } else if (strcmp(sName, __stderr_name) == 0) { 150 | return (STDERR); 151 | } else 152 | return (0); // Not implemented 153 | } 154 | 155 | /********************************************************************* 156 | * 157 | * _sys_close 158 | * 159 | * Function description: 160 | * Closes the handle to the open device/file 161 | * 162 | * Parameters: 163 | * hFile - Handle to a file opened via _sys_open 164 | * 165 | * Return value: 166 | * 0 - device/file closed 167 | * 168 | */ 169 | int _sys_close(FILEHANDLE hFile) { 170 | (void)hFile; 171 | return 0; // Not implemented 172 | } 173 | 174 | /********************************************************************* 175 | * 176 | * _sys_write 177 | * 178 | * Function description: 179 | * Writes the data to an open handle. 180 | * Currently this function only outputs data to the console 181 | * 182 | * Parameters: 183 | * hFile - Handle to a file opened via _sys_open 184 | * pBuffer - Pointer to the data that shall be written 185 | * NumBytes - Number of bytes to write 186 | * Mode - The Mode that shall be used 187 | * 188 | * Return value: 189 | * Number of bytes *not* written to the file/device 190 | * 191 | */ 192 | int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) { 193 | int r = 0; 194 | 195 | (void)Mode; 196 | if (hFile == STDOUT) { 197 | return NumBytes - SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes); 198 | } 199 | return r; 200 | } 201 | 202 | /********************************************************************* 203 | * 204 | * _sys_read 205 | * 206 | * Function description: 207 | * Reads data from an open handle. 208 | * Currently this modules does nothing. 209 | * 210 | * Parameters: 211 | * hFile - Handle to a file opened via _sys_open 212 | * pBuffer - Pointer to buffer to store the read data 213 | * NumBytes - Number of bytes to read 214 | * Mode - The Mode that shall be used 215 | * 216 | * Return value: 217 | * Number of bytes read from the file/device 218 | * 219 | */ 220 | int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) { 221 | (void)hFile; 222 | (void)pBuffer; 223 | (void)NumBytes; 224 | (void)Mode; 225 | return (0); // Not implemented 226 | } 227 | 228 | /********************************************************************* 229 | * 230 | * _sys_istty 231 | * 232 | * Function description: 233 | * This function shall return whether the opened file 234 | * is a console device or not. 235 | * 236 | * Parameters: 237 | * hFile - Handle to a file opened via _sys_open 238 | * 239 | * Return value: 240 | * 1 - Device is a console 241 | * 0 - Device is not a console 242 | * 243 | */ 244 | int _sys_istty(FILEHANDLE hFile) { 245 | if (hFile > 0x8000) { 246 | return (1); 247 | } 248 | return (0); // Not implemented 249 | } 250 | 251 | /********************************************************************* 252 | * 253 | * _sys_seek 254 | * 255 | * Function description: 256 | * Seeks via the file to a specific position 257 | * 258 | * Parameters: 259 | * hFile - Handle to a file opened via _sys_open 260 | * Pos - 261 | * 262 | * Return value: 263 | * int - 264 | * 265 | */ 266 | int _sys_seek(FILEHANDLE hFile, long Pos) { 267 | (void)hFile; 268 | (void)Pos; 269 | return (0); // Not implemented 270 | } 271 | 272 | /********************************************************************* 273 | * 274 | * _sys_ensure 275 | * 276 | * Function description: 277 | * 278 | * 279 | * Parameters: 280 | * hFile - Handle to a file opened via _sys_open 281 | * 282 | * Return value: 283 | * int - 284 | * 285 | */ 286 | int _sys_ensure(FILEHANDLE hFile) { 287 | (void)hFile; 288 | return (-1); // Not implemented 289 | } 290 | 291 | /********************************************************************* 292 | * 293 | * _sys_flen 294 | * 295 | * Function description: 296 | * Returns the length of the opened file handle 297 | * 298 | * Parameters: 299 | * hFile - Handle to a file opened via _sys_open 300 | * 301 | * Return value: 302 | * Length of the file 303 | * 304 | */ 305 | long _sys_flen(FILEHANDLE hFile) { 306 | (void)hFile; 307 | return (0); // Not implemented 308 | } 309 | 310 | /********************************************************************* 311 | * 312 | * _sys_tmpnam 313 | * 314 | * Function description: 315 | * This function converts the file number fileno for a temporary 316 | * file to a unique filename, for example, tmp0001. 317 | * 318 | * Parameters: 319 | * pBuffer - Pointer to a buffer to store the name 320 | * FileNum - file number to convert 321 | * MaxLen - Size of the buffer 322 | * 323 | * Return value: 324 | * 1 - Error 325 | * 0 - Success 326 | * 327 | */ 328 | int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) { 329 | (void)pBuffer; 330 | (void)FileNum; 331 | (void)MaxLen; 332 | return (1); // Not implemented 333 | } 334 | 335 | /********************************************************************* 336 | * 337 | * _sys_command_string 338 | * 339 | * Function description: 340 | * This function shall execute a system command. 341 | * 342 | * Parameters: 343 | * cmd - Pointer to the command string 344 | * len - Length of the string 345 | * 346 | * Return value: 347 | * == NULL - Command was not successfully executed 348 | * == sCmd - Command was passed successfully 349 | * 350 | */ 351 | char * _sys_command_string(char * cmd, int len) { 352 | (void)len; 353 | return cmd; // Not implemented 354 | } 355 | 356 | /********************************************************************* 357 | * 358 | * _sys_exit 359 | * 360 | * Function description: 361 | * This function is called when the application returns from main 362 | * 363 | * Parameters: 364 | * ReturnCode - Return code from the main function 365 | * 366 | * 367 | */ 368 | void _sys_exit(int ReturnCode) { 369 | (void)ReturnCode; 370 | while (1); // Not implemented 371 | } 372 | 373 | #endif 374 | /*************************** End of file ****************************/ 375 | -------------------------------------------------------------------------------- /drivers/SEGGER_RTT_V654c/Syscalls/SEGGER_RTT_Syscalls_SES.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2018 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * conditions are met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this list of conditions and the following disclaimer. * 28 | * * 29 | * o Redistributions in binary form must reproduce the above * 30 | * copyright notice, this list of conditions and the following * 31 | * disclaimer in the documentation and/or other materials provided * 32 | * with the distribution. * 33 | * * 34 | * o Neither the name of SEGGER Microcontroller GmbH * 35 | * nor the names of its contributors may be used to endorse or * 36 | * promote products derived from this software without specific * 37 | * prior written permission. * 38 | * * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 40 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 41 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 42 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 43 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 44 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 45 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 46 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 47 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 49 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 50 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 51 | * DAMAGE. * 52 | * * 53 | ********************************************************************** 54 | ---------------------------END-OF-HEADER------------------------------ 55 | File : SEGGER_RTT_Syscalls_SES.c 56 | Purpose : Reimplementation of printf, puts and __getchar using RTT 57 | in SEGGER Embedded Studio. 58 | To use RTT for printf output, include this file in your 59 | application. 60 | Revision: $Rev: 12804 $ 61 | ---------------------------------------------------------------------- 62 | */ 63 | #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) 64 | 65 | #include "SEGGER_RTT.h" 66 | #include 67 | #include 68 | #include "limits.h" 69 | #include "__libc.h" 70 | #include "__vfprintf.h" 71 | 72 | /********************************************************************* 73 | * 74 | * Defines, configurable 75 | * 76 | ********************************************************************** 77 | */ 78 | // 79 | // Select string formatting implementation. 80 | // 81 | // RTT printf formatting 82 | // - Configurable stack usage. (SEGGER_RTT_PRINTF_BUFFER_SIZE in SEGGER_RTT_Conf.h) 83 | // - No maximum string length. 84 | // - Limited conversion specifiers and flags. (See SEGGER_RTT_printf.c) 85 | // Standard library printf formatting 86 | // - Configurable formatting capabilities. 87 | // - Full conversion specifier and flag support. 88 | // - Maximum string length has to be known or (slightly) slower character-wise output. 89 | // 90 | // #define PRINTF_USE_SEGGER_RTT_FORMATTING 0 // Use standard library formatting 91 | // #define PRINTF_USE_SEGGER_RTT_FORMATTING 1 // Use RTT formatting 92 | // 93 | #ifndef PRINTF_USE_SEGGER_RTT_FORMATTING 94 | #define PRINTF_USE_SEGGER_RTT_FORMATTING 0 95 | #endif 96 | // 97 | // If using standard library formatting, 98 | // select maximum output string buffer size or character-wise output. 99 | // 100 | // #define PRINTF_BUFFER_SIZE 0 // Use character-wise output 101 | // #define PRINTF_BUFFER_SIZE 128 // Default maximum string length 102 | // 103 | #ifndef PRINTF_BUFFER_SIZE 104 | #define PRINTF_BUFFER_SIZE 128 105 | #endif 106 | 107 | #if PRINTF_USE_SEGGER_RTT_FORMATTING // Use SEGGER RTT formatting implementation 108 | /********************************************************************* 109 | * 110 | * Function prototypes 111 | * 112 | ********************************************************************** 113 | */ 114 | int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList); 115 | 116 | /********************************************************************* 117 | * 118 | * Global functions, printf 119 | * 120 | ********************************************************************** 121 | */ 122 | /********************************************************************* 123 | * 124 | * printf() 125 | * 126 | * Function description 127 | * print a formatted string using RTT and SEGGER RTT formatting. 128 | */ 129 | int printf(const char *fmt,...) { 130 | int n; 131 | va_list args; 132 | 133 | va_start (args, fmt); 134 | n = SEGGER_RTT_vprintf(0, fmt, &args); 135 | va_end(args); 136 | return n; 137 | } 138 | 139 | #elif PRINTF_BUFFER_SIZE == 0 // Use standard library formatting with character-wise output 140 | 141 | /********************************************************************* 142 | * 143 | * Static functions 144 | * 145 | ********************************************************************** 146 | */ 147 | static int _putchar(int x, __printf_tag_ptr ctx) { 148 | (void)ctx; 149 | SEGGER_RTT_Write(0, (char *)&x, 1); 150 | return x; 151 | } 152 | 153 | /********************************************************************* 154 | * 155 | * Global functions, printf 156 | * 157 | ********************************************************************** 158 | */ 159 | /********************************************************************* 160 | * 161 | * printf() 162 | * 163 | * Function description 164 | * print a formatted string character-wise, using RTT and standard 165 | * library formatting. 166 | */ 167 | int printf(const char *fmt, ...) { 168 | int n; 169 | va_list args; 170 | __printf_t iod; 171 | 172 | va_start(args, fmt); 173 | iod.string = 0; 174 | iod.maxchars = INT_MAX; 175 | iod.output_fn = _putchar; 176 | SEGGER_RTT_LOCK(); 177 | n = __vfprintf(&iod, fmt, args); 178 | SEGGER_RTT_UNLOCK(); 179 | va_end(args); 180 | return n; 181 | } 182 | 183 | #else // Use standard library formatting with static buffer 184 | 185 | /********************************************************************* 186 | * 187 | * Global functions, printf 188 | * 189 | ********************************************************************** 190 | */ 191 | /********************************************************************* 192 | * 193 | * printf() 194 | * 195 | * Function description 196 | * print a formatted string using RTT and standard library formatting. 197 | */ 198 | int printf(const char *fmt,...) { 199 | int n; 200 | char aBuffer[PRINTF_BUFFER_SIZE]; 201 | va_list args; 202 | 203 | va_start (args, fmt); 204 | n = vsnprintf(aBuffer, sizeof(aBuffer), fmt, args); 205 | if (n > (int)sizeof(aBuffer)) { 206 | SEGGER_RTT_Write(0, aBuffer, sizeof(aBuffer)); 207 | } else if (n > 0) { 208 | SEGGER_RTT_Write(0, aBuffer, n); 209 | } 210 | va_end(args); 211 | return n; 212 | } 213 | #endif 214 | 215 | /********************************************************************* 216 | * 217 | * Global functions 218 | * 219 | ********************************************************************** 220 | */ 221 | /********************************************************************* 222 | * 223 | * puts() 224 | * 225 | * Function description 226 | * print a string using RTT. 227 | */ 228 | int puts(const char *s) { 229 | return SEGGER_RTT_WriteString(0, s); 230 | } 231 | 232 | /********************************************************************* 233 | * 234 | * __putchar() 235 | * 236 | * Function description 237 | * Write one character via RTT. 238 | */ 239 | int __putchar(int x, __printf_tag_ptr ctx) { 240 | (void)ctx; 241 | SEGGER_RTT_Write(0, (char *)&x, 1); 242 | return x; 243 | } 244 | 245 | /********************************************************************* 246 | * 247 | * __getchar() 248 | * 249 | * Function description 250 | * Wait for and get a character via RTT. 251 | */ 252 | int __getchar() { 253 | return SEGGER_RTT_WaitKey(); 254 | } 255 | 256 | #endif 257 | /****** End Of File *************************************************/ 258 | -------------------------------------------------------------------------------- /drivers/mbed-rtt/mbed-rtt.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "mbed-rtt.h" 3 | #include "SEGGER_RTT.h" 4 | 5 | #define MBED_SEGGER_RTT_TERMINAL_INDEX 0 6 | 7 | SeggerRTT::SeggerRTT(void) 8 | { 9 | /* Initialize ITM using internal init function. */ 10 | SEGGER_RTT_ConfigUpBuffer(MBED_SEGGER_RTT_TERMINAL_INDEX, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP); 11 | } 12 | 13 | ssize_t SeggerRTT::write(const void *buffer, size_t size) 14 | { 15 | SEGGER_RTT_Write(MBED_SEGGER_RTT_TERMINAL_INDEX, buffer, size); 16 | 17 | return size; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /drivers/mbed-rtt/mbed-rtt.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MBED_SEGGER_RTT_H 3 | #define MBED_SEGGER_RTT_H 4 | 5 | #include "platform/platform.h" 6 | 7 | #include "platform/FileHandle.h" 8 | 9 | class SeggerRTT : public mbed::FileHandle { 10 | 11 | public: 12 | 13 | SeggerRTT(void); 14 | 15 | virtual ssize_t write(const void *buffer, size_t size); 16 | 17 | virtual ssize_t read(void *buffer, size_t size) 18 | { 19 | /* Reading is not supported by this file handle */ 20 | return -EBADF; 21 | } 22 | 23 | virtual off_t seek(off_t offset, int whence = SEEK_SET) 24 | { 25 | /* Seeking is not support by this file handler */ 26 | return -ESPIPE; 27 | } 28 | 29 | virtual off_t size() 30 | { 31 | /* Size is not defined for this file handle */ 32 | return -EINVAL; 33 | } 34 | 35 | virtual int isatty() 36 | { 37 | /* File handle is used for terminal output */ 38 | return true; 39 | } 40 | 41 | virtual int close() 42 | { 43 | return 0; 44 | } 45 | }; 46 | 47 | 48 | #endif // MBED_SEGGER_RTT_H 49 | -------------------------------------------------------------------------------- /media/pixel-painting.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethitow/mbed-pinetime/4902a8fbbc3e14804e65de94aeef8f87d8579d40/media/pixel-painting.gif -------------------------------------------------------------------------------- /targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_PINETIME_DEV_KIT/PinNames.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA 12 | * integrated circuit in a product or a software update for such product, must reproduce 13 | * the above copyright notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be 17 | * used to endorse or promote products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * 4. This software, with or without modification, must only be used with a 21 | * Nordic Semiconductor ASA integrated circuit. 22 | * 23 | * 5. Any software provided in binary or object form under this license must not be reverse 24 | * engineered, decompiled, modified and/or disassembled. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | */ 38 | 39 | #ifndef MBED_PINNAMES_H 40 | #define MBED_PINNAMES_H 41 | 42 | #include "cmsis.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | typedef enum { 49 | PIN_INPUT, 50 | PIN_OUTPUT 51 | } PinDirection; 52 | 53 | typedef enum { 54 | 55 | // Not connected 56 | NC = (int)0xFFFFFFFF, 57 | 58 | 59 | p0 = 0, 60 | p1 = 1, 61 | p2 = 2, 62 | p3 = 3, 63 | p4 = 4, 64 | p5 = 5, 65 | p6 = 6, 66 | p7 = 7, 67 | p8 = 8, 68 | p9 = 9, 69 | p10 = 10, 70 | p11 = 11, 71 | p12 = 12, 72 | p13 = 13, 73 | p14 = 14, 74 | p15 = 15, 75 | p16 = 16, 76 | p17 = 17, 77 | p18 = 18, 78 | p19 = 19, 79 | p20 = 20, 80 | p21 = 21, 81 | p22 = 22, 82 | p23 = 23, 83 | p24 = 24, 84 | p25 = 25, 85 | p26 = 26, 86 | p27 = 27, 87 | p28 = 28, 88 | p29 = 29, 89 | p30 = 30, 90 | p31 = 31, 91 | 92 | P0_0 = p0, 93 | P0_1 = p1, 94 | P0_2 = p2, 95 | P0_3 = p3, 96 | P0_4 = p4, 97 | P0_5 = p5, 98 | P0_6 = p6, 99 | P0_7 = p7, 100 | 101 | P0_8 = p8, 102 | P0_9 = p9, 103 | P0_10 = p10, 104 | P0_11 = p11, 105 | P0_12 = p12, 106 | P0_13 = p13, 107 | P0_14 = p14, 108 | P0_15 = p15, 109 | 110 | P0_16 = p16, 111 | P0_17 = p17, 112 | P0_18 = p18, 113 | P0_19 = p19, 114 | P0_20 = p20, 115 | P0_21 = p21, 116 | P0_22 = p22, 117 | P0_23 = p23, 118 | 119 | P0_24 = p24, 120 | P0_25 = p25, 121 | P0_26 = p26, 122 | P0_27 = p27, 123 | P0_28 = p28, 124 | P0_29 = p29, 125 | P0_30 = p30, 126 | P0_31 = p31, 127 | 128 | LED1 = p27, 129 | 130 | BUTTON1 = p13, 131 | 132 | // mBed interface Pins 133 | USBTX = NC, 134 | USBRX = NC, 135 | STDIO_UART_TX = NC, 136 | STDIO_UART_RX = NC, 137 | STDIO_UART_CTS = NC, 138 | STDIO_UART_RTS = NC, 139 | 140 | SPI_MOSI = p3, 141 | SPI_MISO = p4, 142 | SPI_SCK = p2, 143 | 144 | SPI_CS_FLASH = p5, 145 | SPI_CS_LCD = p25, 146 | 147 | I2C_SDA = p6, 148 | I2C_SCL = p7, 149 | 150 | PIN_BMA421_INTERRUPT = p8, 151 | PIN_LCD_DET_OUT = p9, 152 | PIN_TOUCHPAD_RESET_OUT = p10, 153 | PIN_CHARGE_INDICATION_IN = p12, 154 | PIN_PUSH_BUTTON_IN = p13, 155 | PIN_PUSH_BUTTON_OUT = p15, 156 | PIN_VIBRATOR_OUT = p16, 157 | PIN_LCD_RS_OUT = p18, 158 | PIN_LCD_RESET_OUT = p26, 159 | PIN_CHARGER_POWER_PRESENT_IN = p19, 160 | PIN_TOUCHPAD_INTERRUPT = p28, 161 | 162 | 163 | 164 | LCD_BACKLIGHT_LOW = p14, 165 | LCD_BACKLIGHT_MID = p22, 166 | LCD_BACKLIGHT_HIGH = p23, 167 | 168 | 169 | BATTERY_VOLTAGE = p31 170 | 171 | 172 | } PinName; 173 | 174 | typedef enum { 175 | PullNone = 0, 176 | PullDown = 1, 177 | PullUp = 3, 178 | PullDefault = PullUp 179 | } PinMode; 180 | 181 | #ifdef __cplusplus 182 | } 183 | #endif 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/TARGET_PINETIME_DEV_KIT/device.h: -------------------------------------------------------------------------------- 1 | // The 'features' section in 'target.json' is now used to create the device's hardware preprocessor switches. 2 | // Check the 'features' section of the target description in 'targets.json' for more details. 3 | /* mbed Microcontroller Library 4 | * Copyright (c) 2006-2013 ARM Limited 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MBED_DEVICE_H 19 | #define MBED_DEVICE_H 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | #include "objects.h" 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /targets/custom_targets.json: -------------------------------------------------------------------------------- 1 | { 2 | "TARGET_PINETIME_DEV_KIT": { 3 | "inherits": [ 4 | "MCU_NRF52832" 5 | ], 6 | "release_versions": [ 7 | "5" 8 | ], 9 | "device_name": "nRF52832_xxAA", 10 | "components_add": [ 11 | "SPIF" 12 | ], 13 | "macros_add": [ 14 | "CONFIG_GPIO_AS_PINRESET", 15 | "NRF52_PAN_12", 16 | "NRF52_PAN_15", 17 | "NRF52_PAN_20", 18 | "NRF52_PAN_30", 19 | "NRF52_PAN_31", 20 | "NRF52_PAN_36", 21 | "NRF52_PAN_51", 22 | "NRF52_PAN_53", 23 | "NRF52_PAN_54", 24 | "NRF52_PAN_55", 25 | "NRF52_PAN_58", 26 | "NRF52_PAN_62", 27 | "NRF52_PAN_63", 28 | "NRF52_PAN_64" 29 | ], 30 | "device_has_add": [ 31 | "STDIO_MESSAGES" 32 | ], 33 | "device_has_remove": [ 34 | "ITM" 35 | ] 36 | } 37 | } --------------------------------------------------------------------------------