Skip to content

Commit

Permalink
get rid of pin lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Jan 22, 2024
1 parent 8b0f5b7 commit 7b41e62
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 74 deletions.
248 changes: 185 additions & 63 deletions errors.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions libs/screen/pins.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "pxt.h"

#include "Pin.h"
#define PinCompat codal::Pin

#define DEV_NUM_PINS 48

namespace pxt {
static DevicePin **pinPtrs;
Expand Down
4 changes: 2 additions & 2 deletions libs/screen/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define BUTTON_ACTIVE_LOW_PULL_UP (ACTIVE_LOW | 0x20)
#define BUTTON_ACTIVE_LOW_PULL_NONE (ACTIVE_LOW | 0x30)

#define PIN(name) ((PinName)pxt::getConfig(CFG_PIN_##name, -1))
#define LOOKUP_PIN(name) pxt::lookupPin(PIN(name))
// #define PIN(name) ((PinName)pxt::getConfig(CFG_PIN_##name, -1))
#define LOOKUP_PIN(name) pxt::lookupPin(CFG_PIN_##name)

// these can be overridden in platform.h
#ifndef CODAL_PIN
Expand Down
131 changes: 131 additions & 0 deletions libs/screen/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#ifndef __PXT_PLATFORM_H
#define __PXT_PLATFORM_H

#include "Image.h"
#include "NRF52SPI.h"
#include "NRF52I2C.h"
#include "NRF52Pin.h"
#include "NRF52PWM.h"
#include "NRF52Serial.h"
#include "NRF52PDM.h"
#include "Timer.h"
#include "MultiButton.h"

#define PAGE_SIZE 4096
#define MIC_DEVICE NRF52PDM

#if defined(NRF52840) || defined(NRF52833)
#define DEV_NUM_PINS 48
#else
#define DEV_NUM_PINS 32
#endif

#define DEV_PWM_PINS 0x0000ffffffffULL // all pins are PWM pins it seems
#define DEV_AIN_PINS 0x0000f000001fULL

// Codal doesn't yet distinguish between PWM and AIN
#define DEV_ANALOG_PINS (DEV_PWM_PINS | DEV_AIN_PINS)

#define CODAL_PIN NRF52Pin
#define CODAL_SPI NRF52SPI
#define CODAL_I2C NRF52I2C
#define CODAL_TIMER Timer
#define CODAL_SERIAL NRF52Serial

#define IMAGE_BITS 4

typedef uint8_t PinName;

#define DEFAULT_NEOPIXEL_PIN P0_0

#define PERF_NOW() (DWT->CYCCNT)
#define PERF_NOW_SCALE 64

// The parameters below needs tuning!

/*
* @param nominalValue The value (in SI units) of a nominal position.
* @param nominalReading The raw reading from the sensor at the nominal position.
* @param beta The Steinhart-Hart Beta constant for the device
* @param seriesResistor The value (in ohms) of the resistor in series with the sensor.
* @param zeroOffset Optional zero offset applied to all SI units (e.g. 273.15 for temperature
* sensing in C vs Kelvin).
*/

#define TEMPERATURE_NOMINAL_VALUE 25
#define TEMPERATURE_NOMINAL_READING 10000
#define TEMPERATURE_BETA 3380
#define TEMPERATURE_SERIES_RESISTOR 10000
#define TEMPERATURE_ZERO_OFFSET 273.5

#define LIGHTSENSOR_SENSITIVITY 868 // codal has 912 now
#define LIGHTSENSOR_LOW_THRESHOLD 128
#define LIGHTSENSOR_HIGH_THRESHOLD 896


#define P0_0 0
#define P0_1 1
#define P0_2 2
#define P0_3 3
#define P0_4 4
#define P0_5 5
#define P0_6 6
#define P0_7 7
#define P0_8 8
#define P0_9 9
#define P0_10 10
#define P0_11 11
#define P0_12 12
#define P0_13 13
#define P0_14 14
#define P0_15 15
#define P0_16 16
#define P0_17 17
#define P0_18 18
#define P0_19 19
#define P0_20 20
#define P0_21 21
#define P0_22 22
#define P0_23 23
#define P0_24 24
#define P0_25 25
#define P0_26 26
#define P0_27 27
#define P0_28 28
#define P0_29 29
#define P0_30 30
#define P0_31 31
#define P1_0 32
#define P1_1 33
#define P1_2 34
#define P1_3 35
#define P1_4 36
#define P1_5 37
#define P1_6 38
#define P1_7 39
#define P1_8 40
#define P1_9 41
#define P1_10 42
#define P1_11 43
#define P1_12 44
#define P1_13 45
#define P1_14 46
#define P1_15 47
#define P1_16 48
#define P1_17 49
#define P1_18 50
#define P1_19 51
#define P1_20 52
#define P1_21 53
#define P1_22 54
#define P1_23 55
#define P1_24 56
#define P1_25 57
#define P1_26 58
#define P1_27 59
#define P1_28 60
#define P1_29 61
#define P1_30 62
#define P1_31 63

#endif
1 change: 0 additions & 1 deletion libs/screen/screen.cpp

This file was deleted.

40 changes: 40 additions & 0 deletions libs/st7735/config_nrf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#define CFG_DISPLAY_WIDTH 160
#define CFG_DISPLAY_HEIGHT = 128
#define CFG_DISPLAY_TYPE 4242 // smart display

#define CFG_DISPLAY_CFG0 0x00000080
#define CFG_DISPLAY_CFG1 0x00000603
#define CFG_DISPLAY_CFG2 8

#define CFG_PIN_DISPLAY_SCK 17 // DAL.P0_17
#define CFG_PIN_DISPLAY_MOSI 13 // DAL.P0_13
#define CFG_PIN_DISPLAY_MISO 1 // DAL.P0_1
#define CFG_PIN_DISPLAY_BL 26 // DAL.P0_26
#define CFG_PIN_DISPLAY_DC 10 // DAL.P0_10
#define CFG_PIN_DISPLAY_RST 34 // DAL.P1_2
#define CDG_PIN_DISPLAY_CS 11 // DAL.P0_11 TODO: check this ???

#define CFG_PIN_LED 13 // DAL.P0_13 TODO

// // there's no UF2 bootloader for 52833 yet, so we specify example configuration here
// namespace config {
// export const PIN_BTNMX_LATCH = DAL.P0_9
// export const PIN_BTNMX_CLOCK = DAL.P1_0
// export const PIN_BTNMX_DATA = DAL.P0_1

// // pybadge-like layout
// export const PIN_BTN_LEFT = 1050
// export const PIN_BTN_UP = 1051
// export const PIN_BTN_DOWN = 1052
// export const PIN_BTN_RIGHT = 1053
// export const PIN_BTN_A = 1054
// export const PIN_BTN_B = 1055
// export const PIN_BTN_MENU = 1056

// export const PIN_JACK_SND = DAL.P0_0

// // Jacdac, when jacdaptor is connected, is on the accessibility pin (P12)
// export const PIN_JACK_TX = DAL.P0_12

//
// }
1 change: 1 addition & 0 deletions libs/st7735/jddisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pxt.h"

#include "jddisplay.h"

#define VLOG NOLOG
Expand Down
1 change: 1 addition & 0 deletions libs/st7735/jddisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "arcadesound.h"

#include "Pin.h"
#define PinCompat codal::Pin

namespace pxt {

Expand Down
7 changes: 5 additions & 2 deletions libs/st7735/panic.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "pxt.h"

#include "Pin.h"
#define PinCompat codal::Pin

#include "config_nrf.h"

// This adds about 1.2k of binary size, but allows for displaying
// panic codes regardless of heap state etc. with IRQs disabled.

Expand Down Expand Up @@ -42,8 +47,6 @@
#define MADCTL_BGR 0x08
#define MADCTL_MH 0x04

typedef MicroBitPin Pin;

namespace _pxt_panic {

// target_panic has been called
Expand Down
14 changes: 8 additions & 6 deletions libs/st7735/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "jddisplay.h"

#include "config_nrf.h"

typedef RefImage *SImage_;

namespace pxt {
Expand All @@ -33,13 +35,13 @@ class WDisplay {
uint32_t palXOR;

WDisplay() {
uint32_t cfg2 = getConfig(CFG_DISPLAY_CFG2, 0x0);
uint32_t cfg2 = CFG_DISPLAY_CFG2;
int conn = cfg2 >> 24;

uint32_t cfg0 = getConfig(CFG_DISPLAY_CFG0, 0x40);
uint32_t frmctr1 = getConfig(CFG_DISPLAY_CFG1, 0x000603);
uint32_t cfg0 = CFG_DISPLAY_CFG0;
uint32_t frmctr1 = CFG_DISPLAY_CFG1;

int dispTp = getConfig(CFG_DISPLAY_TYPE, DISPLAY_TYPE_ST7735);
int dispTp = CFG_DISPLAY_TYPE;

doubleSize = false;
smart = NULL;
Expand Down Expand Up @@ -118,8 +120,8 @@ class WDisplay {
lcd->configure(madctl, frmctr1);
}

width = getConfig(CFG_DISPLAY_WIDTH, 160);
height = getConfig(CFG_DISPLAY_HEIGHT, 128);
width = CFG_DISPLAY_WIDTH;
height = CFG_DISPLAY_HEIGHT;
displayHeight = height;
setAddrMain();
DMESG("screen: %d x %d, off=%d,%d", width, height, offX, offY);
Expand Down

0 comments on commit 7b41e62

Please sign in to comment.