# Notes for a wall mount mini terminal for audio applications

<abstract>
This article contains the feasibility notes to build a wall mount terminal for audio application requested by an Acme customer   
</abstract>

## Feature requested by the customer

* Small Oled display 128x128 with SPI interface
* Stereo class-d output
* Two PDM microphone
* Boot from MMC0 bus (required to use both Class D audio out lines)


## Wirings

### Micro SD on MMC0

Place a 68k pull-up resistor on DATA 0,1,2,3 and CMD


| CPU line | SD Signal  | SD Pin # |
|----------|------------|----------|
| PA0      |  CLK       | 5        |
| PA1      |  CMD       | 2        |
| PA2      |  DATA 0    | 7        |
| PA3      |  DATA 1    | 8        |
| PA4      |  DATA 2    | 9        |
| PA5      |  DATA 3    | 1        |
|          |  VCC       | 4        |
|          |  GND       | 3,6      |
| PA13     |  GND (CD)  |          | 

### Oled display

| Signal     | Berta D2 | ADAFRUIT |
|------------|----------|----------|
| SPI0 MOSI  | PA15     | SI       |
| SPI0 MISO  | PA16     | SO       |
| SPI0 SCLK  | PA14     | CL       |
| SPI0 CS0   | PA17     | OC       |
|            |          |          |
| Reset      | PA9      | R        |
| D/C        | PA12     | DC       |
|            |          |          |
| 3V         | 3V       |  3V      |
| GND        | GND      |  GND     |

### PDMIC

Connessioni microfono e Berta D2

| Signal     | Berta D2 | MP34DT05-A |
|------------|----------|------------|
| 3V         | 3V       | 1 - VDD    |
| 3V         | 3V       | 2 - LR     |
| PDMIC_CLK  | PB27     | 3 - CLK    |
| PDMIC_DAT  | PB26     | 4 - DOUT   |
| GND        | GND      | 5 - GND    |

### CLASS D

| Signal     | Audio     |
|------------|-----------|
| PB1        | CLASSD_R0 |
| PB2        | CLASSD_R1 |
| PB3        | CLASSD_R2 |
| PB4        | CLASSD_R3 |
| PA28       | CLASSD_L0 |
| PA29       | CLASSD_L1 |
| PA30       | CLASSD_L2 |
| PA31       | CLASSD_L3 |

### To put inside ahb section


	sdmmc0: sdio-host@a0000000 {
		bus-width = <4>;
		pinctrl-names = "default";
		no-1-8-v;
		non-removable;	
		pinctrl-0 = <&pinctrl_sdmmc0_default>;
		status = "okay";
	};
	
	sdmmc1: sdio-host@b0000000 {
		bus-width = <4>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_sdmmc1_default>;
	};

	/* Disable USB gadget to set free PA31 used by the Class-D circuitry */

	usb0: gadget@300000 {
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_usba_vbus>;
	};



### To put inside apb section 

	classd: classd@fc048000 {
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_classd_default>;
		/*atmel,pwm-type = "diff";*/
		atmel,pwm-type = "single";
		atmel,non-overlap-time = <0>;
		status = "okay";
	};

	spi0: spi@f8000000 {
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_spi0_default>;
		status = "okay";

		device@0 {
			rotate = <0>;
			bgr;
			fps = <30>;
			compatible = "solomon,ssd1351";
			spi-max-frequency = <20000000>;   
			reg = <0>;
			regwidth = <8>;
			buswidth = <8>;
			verbose = <3>;
			reset-gpios = <&pioA PIN_PA13 0>;
			dc-gpios = <&pioA PIN_PA12 0>;
		};
	};

	pdmic@f8018000 {
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_pdmic_default>;
		atmel,model = "PDMIC @ RoadRunner";
		atmel,mic-min-freq = <1000000>;
		atmel,mic-max-freq = <3246000>;
		atmel,mic-offset = <0x0>;
		status = "okay";
	};

###	To put inside pinctrl@fc038000 section

	pinctrl_classd_default: classd_default {
		pinmux = <PIN_PB1__CLASSD_R0>,
			 <PIN_PB2__CLASSD_R1>,
			 <PIN_PB3__CLASSD_R2>,
			 <PIN_PB4__CLASSD_R3>,
			 <PIN_PA28__CLASSD_L0>,
			 <PIN_PA29__CLASSD_L1>,
			 <PIN_PA30__CLASSD_L2>,
			 <PIN_PA31__CLASSD_L3>;
		bias-pull-up;
	};

	pinctrl_sdmmc0_default: sdmmc0_default {
		cmd_data {
			pinmux = <PIN_PA1__SDMMC0_CMD>,
				 <PIN_PA2__SDMMC0_DAT0>,
				 <PIN_PA3__SDMMC0_DAT1>,
				 <PIN_PA4__SDMMC0_DAT2>,
				 <PIN_PA5__SDMMC0_DAT3>;
			bias-disable;
		};

		ck_cd_rstn_vddsel {
			pinmux = <PIN_PA0__SDMMC0_CK>,
				 <PIN_PA13__SDMMC0_CD>;
			bias-disable;
		};
	};

	pinctrl_pdmic_default: pdmic_default {
		pinmux = <PIN_PB26__PDMIC_DAT>,
			<PIN_PB27__PDMIC_CLK>;
		bias-disable;
	};



### at91bootstrap setup

	Memory selection  --->	
		SD Card Configuration  ---> 
			SD Host Controller Select (On SDHC0)  --->
				(X) On SDHC0
                ( ) On SDHC1

### Kernel setup

Enable Class D support

	Device Drivers > 
		Sound card support > 
			Advanced Linux Sound Architecture > 
				ALSA for SoC audio support 
					<*>   SoC Audio for the Atmel System-on-Chip
					<*>     Atmel ASoC driver for boards using CLASSD


Enable the Kernel support for small TFT LCD with ILI9341 LCD Controller

	Device Drivers  --->
	  [*] Staging drivers  --->
	    <*>   Support for small TFT LCD display modules  --->
	        <*>   FB driver for the SSD1351 LCD Controller

Enable PDMIC

	Device Drivers > 
		Sound card support > 
			Advanced Linux Sound Architecture > 
				ALSA for SoC audio support 
					<*>   SoC Audio for the Atmel System-on-Chip
					<*>     Atmel ASoC driver for boards using PDMIC  


## User space notes

### Disegnare sul display in Python direttamente sul frame buffer

Installare Pittorix

	git https://github.com/robertmuth/Pytorinox.git

Installare PIL e numpy

	sudo apt update
	sudo apt install python3-pil
	sudo apt install python3-numpy

Provare gli esempi su questa pagina:

* <https://raspi.muth.org/framebuffer.html>
			
### Riproduzione video

	sudo mplayer -vo fbdev watch.mov

### PDMIC

	sudo arecord -D hw:1,0 -d 10 -f S16_LE -c1 -r48000 p48000.wav
	sudo arecord -D hw:1,0 -d 10 -f cd -c1 -r48000 p48000.wav
	sudo arecord -D hw:1,0 -d 10 -f cd -c2 -r48000 p48000.wav

### Class D

List the adio devices

	sudo aplay -l
	**** List of PLAYBACK Hardware Devices ****
	card 0: CLASSD [CLASSD], device 0: CLASSD PCM atmel-classd-hifi-0 [CLASSD PCM atmel-classd-hifi-0]
	  Subdevices: 1/1
	  Subdevice #0: subdevice #0	

Play

	sudo mplayer money.m4a 

### Wolfson WM8731

| DAISY-16-V2 | WM8731 | MikroE   | Atmel I2SC | RoadRunner |
|-------------|--------|----------|------------|------------|   
|  1 3V3      |        |          |            |            |
|  2 RF       | ADCLRC | ADCLRC   | I2SC_WS    | PC3        |
|  3 RD       | ADCDAT | ADC-MISO | I2SC_DI    | PC4        |
|  4 TK       | BCLK   | ACD-SCK  | I2SC_CK    | PC1        |
|  5 TF       | DACLRC | DACLRC   | I2SC_WS    | PC3        |
|  6 TD       | DACDAT | ACD-MOSI | I2SC_DO    | PC5        |
|  7 SDA      | SDIN   | I2C-SDA  |            |            |
|  8 SCL      | SCLK   | I2C-SCL  |            |            |
|  9 RK       | BCLK   | ACD-SCK  | I2SC_CK    | PC1        |
| 10 GND      |        |          |            |            |
|             |        |          | I2SC_MCK   | PC2        |  

* <https://www.linux4sam.org/bin/view/Linux4SAM/UsingI2SC>
* [Wolfson WM8731 datasheet](https://statics.cirrus.com/pubs/proDatasheet/WM8731_v4.9.pdf)

## Hardware notes

<img src="./sdpins.png" width="360px">

## Links

Microfono ST MP34DT05-A (Scheda du valutazione ST)

* [Datasheet MP34DT05-A](https://www.st.com/resource/en/datasheet/mp34dt05-a.pdf)

Microfono PDMIC WM7211 (obsoleto)

* [How to use record audio stream with PDMIC Cyrrus Logic WM7211](https://www.linux4sam.org/bin/view/Linux4SAM/PDMICAudioRecord)
* [Datasheet WM7211](https://d3uzseaevmutz1.cloudfront.net/pubs/proDatasheet/WM7211_v4.0.pdf)

Alternativa Microfono PDMIC ST MP34DT01-M 

* [Datasheet](https://www.mouser.it/datasheet/2/389/mp34dt01-m-955068.pdf)
* [Scheda di valutazione Adatfuit](https://www.digikey.it/product-detail/it/adafruit-industries-llc/3492/1528-2521-ND/8130887?utm_adgroup=Evaluation%20and%20Demonstration%20Boards%20and%20Kits&utm_source=google&utm_medium=cpc&utm_campaign=Shopping_Product_Development%20Boards%2C%20Kits%2C%20Programmers_NEW&utm_term=&productid=8130887&gclid=CjwKCAjwjqT5BRAPEiwAJlBuBShNTlaIXCNfG_9V7urAr_LSdvhf9FjX1nt7hqmHf-bM4oNds8g64BoC7LEQAvD_BwE)

@include='bio_tanzilli'

 
