Skip to content

Commit

Permalink
[example] Add SAMD21 Xplained Pro usb serial example
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Sep 29, 2022
1 parent 9adb9fa commit 8c9b4d8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/samd21_xplained_pro/usbserial/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2016-2017, Niklas Hauser
* Copyright (c) 2022, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>
#include <modm/processing/timer.hpp>

using namespace Board;

modm::IODeviceWrapper<UsbUart0, modm::IOBuffer::BlockIfFull> usb_io_device;
modm::IOStream usb_stream(usb_io_device);

int
main()
{
Board::initialize();
Board::initializeUsbFs();

tusb_init();

usb_stream << "Hello from USB" << modm::endl;

uint32_t counter(0);

modm::PeriodicTimer timer{500ms};
while (true)
{
tud_task();
if (timer.execute()) {
Led0::toggle();
usb_stream << "loop: " << counter++ << modm::endl;
}
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/samd21_xplained_pro/usbserial/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:samd21-xplained-pro</extends>
<options>
<option name="modm:tinyusb:config">device.cdc</option>
<option name="modm:build:build.path">../../../build/samd21_xplained_pro/usbserial</option>
</options>
<modules>
<module>modm:tinyusb</module>
<module>modm:build:scons</module>
<module>modm:processing:timer</module>
</modules>
</library>

0 comments on commit 8c9b4d8

Please sign in to comment.