Skip to content

PCB Modules Validator #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
205 changes: 0 additions & 205 deletions draft/display.circ

This file was deleted.

43 changes: 43 additions & 0 deletions planner/pcb/validator/mod_ram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from planner.pcb.validator import rasp


# From module prespective
PIN_ADDRESS_IN = list(range(2,10))
PIN_VALUE_IN = list(range(10,18))
PIN_VALUE_OUT = list(range(18,26))
PIN_IS_WRITE = 26
PIN_CLK = 27


class ModRamValidator:
'''Validate RAM sub-module.

RAM sub-module is equally divided
- At 1/4 at value line.
- At 1/2 at address line.

RAM module will export
- Input: 2*8 bits address line
- Input: 4*8 bits value line
- Output: 32 bits value line
- Input: 1 bit is_write
- Input: 1 bit clk
'''
def __init__(self, r: rasp.PiController):
self.r = r

def setup(self):
# from validator prespective
address_out = [self.r.assign_out(p) for p in PIN_ADDRESS_IN]
value_out = [self.r.assign_out(p) for p in PIN_VALUE_IN]
value_in = [self.r.assign_in(p) for p in PIN_VALUE_OUT]
is_write_out = self.r.assign_out(PIN_IS_WRITE)
is_clk = self.r.assign_out(PIN_CLK)

def execute_write(self, address: int, value: int):
assert address >= 0 and address < (1<<8)
assert value >=0 and value < (1<<8)




53 changes: 53 additions & 0 deletions planner/pcb/validator/rasp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import atexit

import RPi.GPIO as GPIO

RESERVED_PINS = set([0, 1])

class PiPin:
def __init__(self, pin: int):
assert pin not in RESERVED_PINS
assert pin in list(range(28))
self.pin = pin

class PiOut(PiPin):
def __init__(self, *args):
super().__init__(*args)
GPIO.setup(self.pin, GPIO.OUT)

def set(self, high: bool):
GPIO.output(self.pin, GPIO.HIGH if high else GPIO.LOW)

class PiInput(PiPin):
def __init__(self, *args):
super().__init__(*args)
GPIO.setup(self.pin, GPIO.IN)

def is_high(self):
return GPIO.input(self.pin) == GPIO.HIGH


class PiController:
def __init__(self):
self.pins = [None]*28 # pytype: List[PiPin | None]
self.setup()

def setup(self):
def cleanup():
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup
atexit.register(cleanup)

def assign_out(self, index: int):
assert self.pins[index] is None
out = PiOut(index)
self.pins[index] = out
return out

def assign_in(self, index: int):
assert index not in self.reserved_pins
assert self.pins[index] is None
input = PiInput(index)
self.pins[index] = input
return input