-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
[ CKSDK ] | ||
Copyright 2023 Regan "CKDEV" Green | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
/// @file CKSDK/PIO.h | ||
/// @brief CKSDK PIO API | ||
|
||
#pragma once | ||
|
||
#include <CKSDK/CKSDK.h> | ||
|
||
#include <CKSDK/OS.h> | ||
|
||
/// @brief CKSDK namespace | ||
namespace CKSDK | ||
{ | ||
/// @brief CKSDK PIO namespace | ||
namespace PIO | ||
{ | ||
// PIO functions | ||
/// @brief Check if there is a PIO device connected | ||
/// @return True if there is a device connected, false otherwise | ||
static inline bool Connected() | ||
{ | ||
return OS::PioStatus() != 0xFF; | ||
} | ||
|
||
/// @brief Gheck if the PIO FIFO has data | ||
/// @return True if the FIFO has data, false otherwise | ||
/// @note This function assumes that there is a device connected, if not, it will return true | ||
static inline bool HasData() | ||
{ | ||
return OS::PioStatus() & 0x01; | ||
} | ||
|
||
/// @brief Check if the PIO FIFO is full | ||
/// @return True if the FIFO is full, false otherwise | ||
/// @note This function assumes that there is a device connected, if not, it will return true | ||
static inline bool IsFull() | ||
{ | ||
return OS::PioStatus() & 0x02; | ||
} | ||
|
||
/// @brief Flush the PIO FIFO | ||
/// @note This function assumes that there is a device connected, will freeze otherwise | ||
static inline void Flush() | ||
{ | ||
while (HasData()) | ||
OS::PioData(); | ||
} | ||
|
||
/// @brief Read a byte from the PIO FIFO | ||
/// @return The byte read from the FIFO | ||
/// @note This function will block until there is data in the FIFO, it assumes that there is a device connected, will freeze otherwise | ||
static inline uint8_t Read() | ||
{ | ||
while (!HasData()); | ||
return OS::PioData(); | ||
} | ||
|
||
/// @brief Write a byte to the PIO FIFO | ||
/// @param data The byte to write to the FIFO | ||
/// @note This function will block until there is space in the FIFO, it assumes that there is a device connected, will freeze otherwise | ||
static inline void Write(uint8_t data) | ||
{ | ||
while (IsFull()); | ||
OS::PioData(data); | ||
} | ||
} | ||
} |