Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions src/machine/board_arduino_unor4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//go:build arduino_unor4

// This contains the pin mappings for the Arduino Uno R4 board.
//
// For more information, see:
package machine

// GPIO Pins
const (
D0 Pin = P3_01
D1 Pin = P3_02
D2 Pin = P1_04
D3 Pin = P1_05
D4 Pin = P1_06
D5 Pin = P1_07
D6 Pin = P1_11
D7 Pin = P1_12
D8 Pin = P3_04
D9 Pin = P3_03
D10 Pin = P1_03
D11 Pin = P4_11
D12 Pin = P4_10
D13 Pin = P1_02
)

// Analog pins
const (
A0 Pin = P0_14
A1 Pin = P0_00
A2 Pin = P0_01
A3 Pin = P0_02
A4 Pin = P1_01
A5 Pin = P1_00
)

const (
LED = D13
)


// UART1 pins
const (
UART_TX_PIN Pin = P1_09
UART_RX_PIN Pin = P1_10
)

// I2C pins
const (
SDA_PIN Pin = A4
SCL_PIN Pin = A5
)

// { BSP_IO_PORT_03_PIN_01, P301 }, /* (0) D0 ------------------------- DIGITAL */
// { BSP_IO_PORT_03_PIN_02, P302 }, /* (1) D1 */
// { BSP_IO_PORT_01_PIN_04, P104 }, /* (2) D2 */
// { BSP_IO_PORT_01_PIN_05, P105 }, /* (3) D3~ */
// { BSP_IO_PORT_01_PIN_06, P106 }, /* (4) D4 */
// { BSP_IO_PORT_01_PIN_07, P107 }, /* (5) D5~ */
// { BSP_IO_PORT_01_PIN_11, P111 }, /* (6) D6~ */
// { BSP_IO_PORT_01_PIN_12, P112 }, /* (7) D7 */
// { BSP_IO_PORT_03_PIN_04, P304 }, /* (8) D8 */
// { BSP_IO_PORT_03_PIN_03, P303 }, /* (9) D9~ */
// { BSP_IO_PORT_01_PIN_03, P103 }, /* (10) D10~ */
// { BSP_IO_PORT_04_PIN_11, P411 }, /* (11) D11~ */
// { BSP_IO_PORT_04_PIN_10, P410 }, /* (12) D12 */
// { BSP_IO_PORT_01_PIN_02, P102 }, /* (13) D13 */
// { BSP_IO_PORT_00_PIN_14, P014 }, /* (14) A0 -------------------------- ANALOG */
// { BSP_IO_PORT_00_PIN_00, P000 }, /* (15) A1 */
// { BSP_IO_PORT_00_PIN_01, P001 }, /* (16) A2 */
// { BSP_IO_PORT_00_PIN_02, P002 }, /* (17) A3 */
// { BSP_IO_PORT_01_PIN_01, P101 }, /* (18) A4/SDA */
// { BSP_IO_PORT_01_PIN_00, P100 }, /* (19) A5/SCL */

// { BSP_IO_PORT_05_PIN_00, P500 }, /* (20) Analog voltage measure pin */
// { BSP_IO_PORT_04_PIN_08, P408 }, /* (21) USB switch, drive high for RA4 */

// { BSP_IO_PORT_01_PIN_09, P109 }, /* (22) D22 ------------------------ TX */
// { BSP_IO_PORT_01_PIN_10, P110 }, /* (23) D23 ------------------------ RX */
// { BSP_IO_PORT_05_PIN_01, P501 }, /* (24) D24 ------------------------- TX WIFI */
// { BSP_IO_PORT_05_PIN_02, P502 }, /* (25) D25 ------------------------- RX WIFI */

// { BSP_IO_PORT_04_PIN_00, P400 }, /* (26) D26 QWIC SCL */
// { BSP_IO_PORT_04_PIN_01, P401 }, /* (27) D27 QWIC SDA */

// { BSP_IO_PORT_00_PIN_03, P003 }, /* (28) D28 */
// { BSP_IO_PORT_00_PIN_04, P004 }, /* (29) D29 */
// { BSP_IO_PORT_00_PIN_11, P011 }, /* (30) D30 */
// { BSP_IO_PORT_00_PIN_12, P012 }, /* (31) D31 */
// { BSP_IO_PORT_00_PIN_13, P013 }, /* (32) D32 */
// { BSP_IO_PORT_00_PIN_15, P015 }, /* (33) D33 */
// { BSP_IO_PORT_02_PIN_04, P204 }, /* (34) D34 */
// { BSP_IO_PORT_02_PIN_05, P205 }, /* (35) D35 */
// { BSP_IO_PORT_02_PIN_06, P206 }, /* (36) D36 */
// { BSP_IO_PORT_02_PIN_12, P212 }, /* (37) D37 */
// { BSP_IO_PORT_02_PIN_13, P213 }, /* (38) D38 */
236 changes: 236 additions & 0 deletions src/machine/machine_ra4m1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
//go:build ra4m1

package machine

import (
"device/renesas"
"runtime/volatile"
"unsafe"
)

const deviceName = renesas.Device

const (
P0_00 Pin = 0
P0_01 Pin = 1
P0_02 Pin = 2
P0_03 Pin = 3
P0_04 Pin = 4
P0_05 Pin = 5
P0_06 Pin = 6
P0_07 Pin = 7
P0_08 Pin = 8
P0_09 Pin = 9
P0_10 Pin = 10
P0_11 Pin = 11
P0_12 Pin = 12
P0_13 Pin = 13
P0_14 Pin = 14
P0_15 Pin = 15
P1_00 Pin = 16
P1_01 Pin = 17
P1_02 Pin = 18
P1_03 Pin = 19
P1_04 Pin = 20
P1_05 Pin = 21
P1_06 Pin = 22
P1_07 Pin = 23
P1_08 Pin = 24
P1_09 Pin = 25
P1_10 Pin = 26
P1_11 Pin = 27
P1_12 Pin = 28
P1_13 Pin = 29
P1_14 Pin = 30
P1_15 Pin = 31
P2_00 Pin = 32
P2_01 Pin = 33
P2_02 Pin = 34
P2_03 Pin = 35
P2_04 Pin = 36
P2_05 Pin = 37
P2_06 Pin = 38
P2_07 Pin = 39
P2_08 Pin = 40
P2_09 Pin = 41
P2_10 Pin = 42
P2_11 Pin = 43
P2_12 Pin = 44
P2_13 Pin = 45
P2_14 Pin = 46
P2_15 Pin = 47
P3_00 Pin = 48
P3_01 Pin = 49
P3_02 Pin = 50
P3_03 Pin = 51
P3_04 Pin = 52
P3_05 Pin = 53
P3_06 Pin = 54
P3_07 Pin = 55
P3_08 Pin = 56
P3_09 Pin = 57
P3_10 Pin = 58
P3_11 Pin = 59
P3_12 Pin = 60
P3_13 Pin = 61
P3_14 Pin = 62
P3_15 Pin = 63
P4_00 Pin = 64
P4_01 Pin = 65
P4_02 Pin = 66
P4_03 Pin = 67
P4_04 Pin = 68
P4_05 Pin = 69
P4_06 Pin = 70
P4_07 Pin = 71
P4_08 Pin = 72
P4_09 Pin = 73
P4_10 Pin = 74
P4_11 Pin = 75
P4_12 Pin = 76
P4_13 Pin = 77
P4_14 Pin = 78
P4_15 Pin = 79
P5_00 Pin = 80
P5_01 Pin = 81
P5_02 Pin = 82
P5_03 Pin = 83
P5_04 Pin = 84
P5_05 Pin = 85
P5_06 Pin = 86
P5_07 Pin = 87
P5_08 Pin = 88
P5_09 Pin = 89
P5_10 Pin = 90
P5_11 Pin = 91
P5_12 Pin = 92
P5_13 Pin = 93
P5_14 Pin = 94
P5_15 Pin = 95
)

const (
PinOutput PinMode = iota
PinInput
PinInputPullUp
PinInputPullDown
)

// Configure configures the gpio pin as per mode.
func (p Pin) Configure(config PinConfig) {
if p == NoPin {
return
}

enableWritingPmnPFS()

switch config.Mode {
case PinOutput:
setPDR(p, renesas.PFS_P000PFS_PDR_1)
default:
setPDR(p, renesas.PFS_P000PFS_PDR_0)
}

disableWritingPmnPFS()
}

// Set drives the pin high if value is true else drives it low.
func (p Pin) Set(value bool) {
if p == NoPin {
return
}

port := getPort(p)
if port == nil {
return
}

if value == true {
port.set(p)
} else {
port.clr(p)
}
}

// Get reads the pin value.
func (p Pin) Get() bool {
return false
}

var (
gpioPort0 = gpioPortType0{renesas.PORT0}
gpioPort1 = gpioPortType1{renesas.PORT1}
gpioPort2 = gpioPortType1{renesas.PORT2}
gpioPort3 = gpioPortType1{renesas.PORT3}
gpioPort4 = gpioPortType1{renesas.PORT4}
gpioPort5 = gpioPortType0{renesas.PORT5}
)

func getPort(p Pin) gpioPort {
switch getPortNumber(p) {
case 0:
return gpioPort0
case 1:
return gpioPort1
case 2:
return gpioPort2
case 3:
return gpioPort3
case 4:
return gpioPort4
case 5:
return gpioPort5
default:
return nil
}
}

func getPortNumber(p Pin) int {
return int(p) >> 8
}

type gpioPort interface {
set(p Pin)
clr(p Pin)
}

type gpioPortType0 struct {
port *renesas.PORT0_Type
}

func (p gpioPortType0) set(pin Pin) {
p.port.SetPCNTR3_PORR(1 << pin)
}

func (p gpioPortType0) clr(pin Pin) {
p.port.SetPCNTR3_POSR(1 << pin)
}

type gpioPortType1 struct {
port *renesas.PORT1_Type
}

func (p gpioPortType1) set(pin Pin) {
p.port.SetPCNTR3_PORR(1 << pin)
}

func (p gpioPortType1) clr(pin Pin) {
p.port.SetPCNTR3_POSR(1 << pin)
}

func enableWritingPmnPFS() {
renesas.PMISC.PWPR.Set(0x0)
renesas.PMISC.SetPWPR_PFSWE(0x1)
}

func disableWritingPmnPFS() {
renesas.PMISC.PWPR.Set(0x0)
renesas.PMISC.SetPWPR_B0WI(0x1)
}

func setPDR(p Pin, value uint32) {
port := getPortNumber(p)
bit := int(p) & 0xff
reg := (*volatile.Register32)(unsafe.Add(unsafe.Pointer(uintptr(0x40040800)), 0x40*port+4*bit))
reg.SetBits(value << renesas.PFS_P000PFS_PDR_Pos)
}
Loading
Loading