Skip to content

Commit

Permalink
Merge pull request #415 from getoffmyhack/master
Browse files Browse the repository at this point in the history
Hardware SPI support for ATmega128
  • Loading branch information
olikraus committed May 31, 2016
2 parents ec0acc2 + 807fbd0 commit 3922dd8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions csrc/u8g_com_atmega_hw_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,25 @@ uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
u8g_SetPIOutput(u8g, U8G_PI_RESET);

U8G_ATOMIC_START();

#if defined (__AVR_ATmega128__)

DDRB |= _BV(2); /* D0, MOSI */
DDRB |= _BV(1); /* SCK */
DDRB |= _BV(0); /* slave select */

PORTB &= ~_BV(2); /* D0, MOSI = 0 */
PORTB &= ~_BV(1); /* SCK = 0 */
#else

DDRB |= _BV(3); /* D0, MOSI */
DDRB |= _BV(5); /* SCK */
DDRB |= _BV(2); /* slave select */

PORTB &= ~_BV(3); /* D0, MOSI = 0 */
PORTB &= ~_BV(5); /* SCK = 0 */

#endif

U8G_ATOMIC_END();

Expand Down Expand Up @@ -136,7 +148,11 @@ uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
}
else
{
#if defined (__AVR_ATmega128__)
PORTB &= ~_BV(1); /* SCK = 0 */
#else
PORTB &= ~_BV(5); /* SCK = 0 */
#endif
/* enable */
u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */
}
Expand Down

0 comments on commit 3922dd8

Please sign in to comment.