Merged branch UART and changed get function
This commit is contained in:
@@ -37,7 +37,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define initUART(uart_pair) UARTManager::get(uart_pair)
|
#define getUART(uart_pair) UARTManager::get(uart_pair)
|
||||||
|
|
||||||
class UARTManager{
|
class UARTManager{
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ UART::UART(const UART_Pair pair) : m_UARTPair(pair){
|
|||||||
* The AFR register for GPIO_Typedef* is actually two registers - a low reg and high reg.
|
* The AFR register for GPIO_Typedef* is actually two registers - a low reg and high reg.
|
||||||
* The low reg handles pins 0-7, and the high reg handles 8-15.
|
* The low reg handles pins 0-7, and the high reg handles 8-15.
|
||||||
* Each pin gets 4 bits in the register for AFR0 - AFR7. Hence 8 * 4 = 32 bits.
|
* Each pin gets 4 bits in the register for AFR0 - AFR7. Hence 8 * 4 = 32 bits.
|
||||||
* Each AFR is a different function, look at the DATASHEET (not reference manual) to find these alternate functions
|
* Each AFR is a different function, look at the DATASHEET (not reference manual) to find these alternate function mappings
|
||||||
*/
|
*/
|
||||||
getGPIORegister(Tx_Key).reg->AFR[TxAFR] |= getAFMask(uart_pair.TxMask) << (4 * (Tx_Pin % 8));
|
getGPIORegister(Tx_Key).reg->AFR[TxAFR] |= getAFMask(uart_pair.TxMask) << (4 * (Tx_Pin % 8));
|
||||||
getGPIORegister(Rx_Key).reg->AFR[RxAFR] |= getAFMask(uart_pair.RxMask) << (4 * (Rx_Pin % 8));
|
getGPIORegister(Rx_Key).reg->AFR[RxAFR] |= getAFMask(uart_pair.RxMask) << (4 * (Rx_Pin % 8));
|
||||||
@@ -72,11 +72,11 @@ void UART::sendChar(char c) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UART& UARTManager::get(UART_Pair pair) {
|
UART& UARTManager::get(UART_Pair pair) {
|
||||||
|
|
||||||
//Always reassign since we could be changing to different pins for some reason
|
//Reassign if pair doesn't match
|
||||||
|
if(m_UARTs[getUARTChannel(pair)].m_UARTPair != pair) {
|
||||||
m_UARTs[getUARTChannel(pair)] = UART(pair);
|
m_UARTs[getUARTChannel(pair)] = UART(pair);
|
||||||
|
}
|
||||||
return m_UARTs[getUARTChannel(pair)];
|
return m_UARTs[getUARTChannel(pair)];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ void tim2Handler(){
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
UART uart2 = initUART(UART_Pair::Tx2A2_Rx2A3);
|
UART uart2 = getUART(UART_Pair::Tx2A2_Rx2A3);
|
||||||
|
|
||||||
uart2.begin(115200);
|
uart2.begin(115200);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user