xref: /aosp_15_r20/external/pigweed/pw_stream_uart_mcuxpresso/stream_example.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "pw_status/try.h"
16 #include "pw_stream_uart_mcuxpresso/stream.h"
17 #include "pw_unit_test/framework.h"
18 
19 namespace examples {
20 
UartStreamExample()21 pw::Status UartStreamExample() {
22   // DOCSTAG: [pw_stream_uart_mcuxpresso-UartStreamExample]
23   constexpr uint32_t kFlexcomm = 0;
24   constexpr uint32_t kBaudRate = 115200;
25   std::array<std::byte, 20> kBuffer = {};
26 
27   auto stream = pw::stream::UartStreamMcuxpresso{
28       USART0, kBaudRate, kUSART_ParityDisabled, kUSART_OneStopBit, kBuffer};
29 
30   PW_TRY(stream.Init(CLOCK_GetFlexcommClkFreq(kFlexcomm)));
31 
32   std::array<std::byte, 10> to_write = {};
33   PW_TRY(stream.Write(to_write));
34 
35   // DOCSTAG: [pw_stream_uart_mcuxpresso-UartStreamExample]
36 
37   // Do something else
38 
39   return pw::OkStatus();
40 }
41 
TEST(Stream,Example)42 TEST(Stream, Example) {
43   pw::Status status = UartStreamExample();
44   EXPECT_EQ(status.code(), PW_STATUS_OK);
45 }
46 }  // namespace examples
47