Skip to content

Commit

Permalink
Merge pull request #36 from Luos-io/fix/samd_tx_pin_config
Browse files Browse the repository at this point in the history
Fix samd TX pin config, fix #35
  • Loading branch information
JeromeGalan authored Jan 17, 2022
2 parents 75c2cb2 + dad9ab8 commit 9313ce5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 8 additions & 5 deletions ATSAMD21/luos_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,18 @@ void LuosHAL_SetTxState(uint8_t Enable)
{
if (Enable == true)
{
PORT_REGS->GROUP[COM_TX_PORT].PORT_PINCFG[COM_TX_PIN] &= ~PORT_PINCFG_PULLEN_Msk; // TX push pull
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN] = PORT_PINCFG_RESETVALUE_Msk; // no pin mux / no input / no pull / low streght
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN] |= PORT_PINCFG_PMUXEN_Msk; // mux en
if ((TX_EN_PIN != DISABLE) || (TX_EN_PORT != DISABLE))
{
PORT_REGS->GROUP[TX_EN_PORT].PORT_OUTSET = (1 << TX_EN_PIN); // enable Tx
}
}
else
{
PORT_REGS->GROUP[COM_TX_PORT].PORT_PINCFG[COM_TX_PIN] |= PORT_PINCFG_PULLEN_Msk; // Tx Open drain
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN] = PORT_PINCFG_RESETVALUE_Msk; // no pin mux / no input / no pull / low streght
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN] |= PORT_PINCFG_PULLEN_Msk; // Enable Pull
PORT->Group[COM_TX_PORT].OUTSET = (1 << COM_TX_PIN); // Pull up
if ((TX_EN_PIN != DISABLE) || (TX_EN_PORT != DISABLE))
{
PORT_REGS->GROUP[TX_EN_PORT].PORT_OUTCLR = (1 << TX_EN_PIN); // disable Tx
Expand Down Expand Up @@ -563,9 +566,9 @@ static void LuosHAL_GPIOInit(void)
}

/*Configure GPIO pin : TxPin */
PORT_REGS->GROUP[COM_TX_PORT].PORT_PINCFG[COM_TX_PIN] = PORT_PINCFG_RESETVALUE; // no pin mux / no input / no pull / low streght
PORT_REGS->GROUP[COM_TX_PORT].PORT_PINCFG[COM_TX_PIN] |= PORT_PINCFG_PULLEN_Msk;
PORT_REGS->GROUP[COM_TX_PORT].PORT_PINCFG[COM_TX_PIN] |= PORT_PINCFG_PMUXEN_Msk; // mux en
PORT_REGS->GROUP[COM_TX_PORT].PORT_PINCFG[COM_TX_PIN] = PORT_PINCFG_RESETVALUE; // no pin mux / no input / no pull / low streght
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN] |= PORT_PINCFG_PULLEN_Msk; // Enable Pull
PORT->Group[COM_TX_PORT].OUTSET = (1 << COM_TX_PIN); // Pull up
PORT_REGS->GROUP[COM_TX_PORT].PORT_PMUX[COM_TX_PIN >> 1] |= (COM_TX_AF << (4 * (COM_TX_PIN % 2))); // mux to sercom

/*Configure GPIO pin : RxPin */
Expand Down
11 changes: 7 additions & 4 deletions ATSAMD21_ARDUINO/luos_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ void LuosHAL_SetTxState(uint8_t Enable)
{
if (Enable == true)
{
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg &= ~PORT_PINCFG_PULLEN; // Tx push pull
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg = PORT_PINCFG_RESETVALUE; // no pin mux / no input / no pull / low streght
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg |= PORT_PINCFG_PMUXEN; // mux en
if ((TX_EN_PIN != DISABLE) || (TX_EN_PORT != DISABLE))
{
PORT->Group[TX_EN_PORT].OUTSET.reg = (1 << TX_EN_PIN); // enable Tx
}
}
else
{
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg |= PORT_PINCFG_PULLEN; // Tx open drain
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg = PORT_PINCFG_RESETVALUE; // no pin mux / no input / no pull / low streght
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg |= PORT_PINCFG_PULLEN; // Enable Pull
PORT->Group[COM_TX_PORT].OUTSET.reg = (1 << COM_TX_PIN); // Pull up
if ((TX_EN_PIN != DISABLE) || (TX_EN_PORT != DISABLE))
{
PORT->Group[TX_EN_PORT].OUTCLR.reg = (1 << TX_EN_PIN); // disable Tx
Expand Down Expand Up @@ -551,8 +554,8 @@ static void LuosHAL_GPIOInit(void)

/*Configure GPIO pin : TxPin */
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg = PORT_PINCFG_RESETVALUE; // no pin mux / no input / no pull / low streght
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg |= PORT_PINCFG_PMUXEN; // mux en
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg |= PORT_PINCFG_PULLEN; // Tx open drain
PORT->Group[COM_TX_PORT].PINCFG[COM_TX_PIN].reg |= PORT_PINCFG_PULLEN; // Enable Pull
PORT->Group[COM_TX_PORT].OUTSET.reg = (1 << COM_TX_PIN); // Pull up
PORT->Group[COM_TX_PORT].PMUX[COM_TX_PIN >> 1].reg |= (COM_TX_AF << (4 * (COM_TX_PIN % 2))); // mux to sercom

/*Configure GPIO pin : RxPin */
Expand Down

0 comments on commit 9313ce5

Please sign in to comment.