Yes, fully automatic.nocash wrote: ↑Mon Dec 02, 2019 5:40 pmAh, okay, but once when auto-mode is initialized with correct values... it does then start to work automatically, without further manual updating?profi200 wrote: ↑Sat Nov 30, 2019 6:16 pmFigured out automatic output switching. Bank 0x64 reg 0x45 bit 4 controls the current output and bit 5 selects between manual mode (1) or automatic (0). There is a catch though. Bit 4 must match the current GPIO state or it will be stuck despite enabling auto mode.
After you had posted that, I have checked if any registers change on headphone insert/eject... TSC[64h:2Ch] bit0 seems to be 1=connected, and bit1 sometimes gets set too, but not always.
I guess I should also do some headphone tests on DSi to see if it does switch speakers/headphones automatically, I haven't tested much of the DSi sound hardware yet; because I always had the volume set to zero for avoiding the System Menu music.
Looking at the code comments that you had added recently, I figured out that you had derived most of the TSC initialization constants from the HWCAL0/1.dat file's entries at file offset 2E0h and up:Good to know by itself, and also good because the names for the .dat file entries do imply the TSC register purposes.
Code: Select all
Codec (CDC) (aka TSC) 2E0h 1 u8 DriverGainHP ;TSC[65h:0Ch].bit3-7 2E1h 1 u8 DriverGainSP ;TSC[65h:12h].bit2-7 and TSC[65h:13h].bit2-7 2E2h 1 u8 AnalogVolumeHP ;TSC[65h:16h] and TSC[65h:17h] 2E3h 1 u8 AnalogVolumeSP ;TSC[65h:1Bh] and TSC[65h:1Ch] 2E4h 1 s8 ShutterVolume0 ;TSC[00h:41h] and TSC[00h:42h] ;\maybe camera 2E5h 1 s8 ShutterVolume1 ;TSC[64h:7Bh] ;/sound fx? 2E6h 1 u8 MicrophoneBias ;TSC[65h:33h] 2E7h 1 u8 QuickCharge (???) ;TSC[65h:42h].bit0-1 2E8h 1 u8 PGA_GAIN (mic) ;TSC[65h:41h].bit0-5 2E9h 3 u8 reserved 2ECh 1Eh s16 FilterHP32[3*5] ;TSC[0Bh:02h..1Fh] and TSC[0Bh:42h..5Fh] 30Ah 1Eh s16 FilterHP47[3*5] ;TSC[0Bh:20h..3Dh] and TSC[0Bh:60h..7Dh] 328h 1Eh s16 FilterSP32[3*5] ;TSC[0Ch:02h..1Fh] and TSC[0Ch:42h..5Fh] 346h 1Eh s16 FilterSP47[3*5] ;TSC[0Ch:20h..3Dh] and TSC[0Ch:60h..7Dh] 364h 38h s16 FilterMic32[1+2+ (1+4)*5] ;TSC[05h:08h..3Fh], TSC[05h:48h..7Fh] 39Ch 38h s16 FilterMic47[1+2+ (1+4)*5] ;(...same as above...?) 3D4h 38h s16 FilterFree [1+2+ (1+4)*5] ;TSC[08h:xxh, 09h;xxh, 0Ah:xxh] 40Ch 1 u8 AnalogInterval ;\ 40Dh 1 u8 AnalogStabilize ; 40Eh 1 u8 AnalogPrecharge ; 40Fh 1 u8 AnalogSense ; maybe TSC[67h:xxh] ? 410h 1 u8 AnalogDebounce ; 411h 1 u8 Analog_XP_Pullup ; 412h 1 u8 YM_Driver ;/ 413h 1 u8 reserved 414h 2 Checksum? 416h 2 Zero
I am not sure what ShutterVolume means; my only idea would be that it might override slider-volume when playing camera shutter sounds and other alerts(?)
And also unsure what the AnalogXxx values mean, AnalogDebounce sounds touchscreen related, or maybe microphone related.
What does FilterMic47 do? You seem to leave that entry unused, apart from the comment on saying that it is same as FilterMic32... does that mean one of the filters initialized with FilterMic32 is actually FilterMic47?
Oh, and one general thing: The DSi doesn't seem to use any miniDSP instructions anywhere (I don't even know if the TSC chip does actually support them). Would be good to know if the 3ds is using miniDSP code somewhere.
Here is a summary of the used TSC registers, based on your code and on the HWCAL entry names, and with some notes on some further "unused" registers with nonzero values.There are many more unused/zero registers, I haven't tried yet if any of them are R/W, or if there are other ways to get nonzero values into them.
Code: Select all
3DS TSC, Register Summary ------------------------- Page Selection TSC[xxh:00h]=page ;Page (each TSC SPI bus probably has own page+index?) Page 00h-01h (DSi Registers) TSC[00h:02h]=read ;DSi Undocumented status (reserved bits) TSC[00h:03h]=read ;DSi Overtemperature OT Flag (reserved bits) TSC[00h:0Bh]=87h ;DSi DAC NDAC Value TSC[00h:39h]=66h ;DSi ADC DC Measurement 1 (reset=00h, ORed with 66h) TSC[00h:3Fh]=D4h ;DSi DAC Data-Path Setup (reset=D4h, ORed with C0h) TSC[00h:40h]=00h ;DSi DAC Volume Control TSC[00h:41h]=FDh ;DSi DAC Left Volume Control ;\aka 3DS ;HWCAL[2E4h] TSC[00h:42h]=FDh ;DSi DAC Right Volume Control ;/ShutterVol0 ;HWCAL[2E4h] TSC[01h:2Fh]=2Bh ;DSi MIC PGA TSC[01h:30h]=40h ;DSi P-Terminal ADC Channel Fine-Gain Input (reset=40h) TSC[01h:31h]=40h ;DSi M-Terminal ADC Input Selection (reset=40h) The 3DS does usually access only the registers mentioned above (but there are many more DSi-style registers in page 00h,01h,03h; see DSi chapter for details). Page 04h-0Ch (DSi Coefficient RAM) TSC[04h:08h-0Dh]=... ;DSi Some coeff's (7Fh,E1h,80h,1Fh,7Fh,C1h) TSC[05h:08h-3Fh]=... ;3DS FilterMic32 ;HWCAL[364h-39Bh] TSC[05h:48h-7Fh]=... ;3DS FilterMic32, too? Or Mic47? ;HWCAL[xxxh..] TSC[08h:0Ch-3Dh]=... ;3DS FilterFreeB ;\ ;HWCAL[3DAh-40Bh] TSC[08h:4Ch-7Dh]=... ;3DS FilterFreeB' ; initialized for ;HWCAL[3DAh-40Bh] TSC[09h:02h-07h]=... ;3DS FilterFreeA ; non-GBA only ;HWCAL[3D4h-3D9h] TSC[09h:08h-0Dh]=... ;3DS FilterFreeA' ;/ ;HWCAL[3D4h-3D9h] TSC[0Ah:02h-07h]=... ;3DS FilterFreeA'' ;HWCAL[3D4h-3D9h] TSC[0Ah:0Ch-3Dh]=... ;3DS FilterFreeB'' ;HWCAL[3DAh-40Bh] TSC[0Bh:02h-1Fh]=... ;3DS FilterHP32 ;HWCAL[2ECh-309h] TSC[0Bh:20h-3Dh]=... ;3DS FilterHP47 ;HWCAL[30Ah-327h] TSC[0Bh:42h-5Fh]=... ;3DS FilterHP32' ;HWCAL[2ECh-309h] TSC[0Bh:60h-7Dh]=... ;3DS FilterHP47' ;HWCAL[30Ah-327h] TSC[0Ch:02h-1Fh]=... ;3DS FilterSP32 ;HWCAL[328h-345h] TSC[0Ch:20h-3Dh]=... ;3DS FilterSP47 ;HWCAL[346h-363h] TSC[0Ch:42h-5Fh]=... ;3DS FilterSP32' ;HWCAL[328h-345h] TSC[0Ch:60h-7Dh]=... ;3DS FilterSP47' ;HWCAL[346h-363h] The above coefficient RAM pages exists on DSi, too. However, the DSi is usually initializing only those in page 04h. Unknown how the 3DS is using the extra coefficients... does it use miniDSP instructions for that? Page 64h (3DS Sound/Microphone Config) TSC[64h:01h]=01h ;3DS Software Reset (?) TSC[64h:22h]=18h ;3DS ? (reset=00h, ORed with 18h, later bit2=cleared) TSC[64h:25h]=read ;3DS status, wait for bit3,7 TSC[64h:26h]=read ;3DS status, wait for bit3,7 TSC[64h:2Ch] ;unused, but nonzero ;bit0,1=headphone connect status TSC[64h:30h] ;unused, but nonzero TSC[64h:31h]=00h/44h ;3DS ? (reset=00h) (GBA:00h, Other:44h) TSC[64h:43h]=11h/91h ;3DS set to 11h, later toggles bit=0 then bit7=1 TSC[64h:44h] ;unused, but nonzero TSC[64h:45h]=20h/30h ;3DS Speaker off (reset=00h, later=20h, 30h=speakerOff) TSC[64h:75h] ;unused, but nonzero TSC[64h:76h]=14h/D4h ;3DS ? (reset=14h, ORed with C0h) TSC[64h:77h]=0Ch/00h ;3DS ? (reset=0Ch, later clear bit2,3 after coeff init) TSC[64h:78h]=00h ;3DS ? TSC[64h:7Ah]=00h ;3DS ? TSC[64h:7Bh]=ECh ;3DS ShutterVolume1 ;HWCAL[2E5h] TSC[64h:7Ch]=0Ah ;3DS ? (reset=0Ah, later clears bit0) Page 65h (3DS Sound/Microphone Gains) TSC[65h:0Ah]=0Ah ;3DS ? TSC[65h:0Bh]=1Ch/3Ch ;3DS ? ... depends on TSC[00h:02h..03h] TSC[65h:0Ch]=04h ;3DS DriverGainHP ;HWCAL[2E0h]*8+4 TSC[65h:11h]=10h/D0h ;3DS ? (reset=00h, ORed with 10h, later ORed with C0h) TSC[65h:12h]=06h ;3DS DriverGainSP ;\maybe left? ;HWCAL[2E1h]*4+2 TSC[65h:13h]=06h ;3DS DriverGainSP' ;/ right? ;HWCAL[2E1h]*4+2 TSC[65h:16h]=00h ;3DS AnalogVolumeHP ;\maybe left? ;HWCAL[2E2h] TSC[65h:17h]=00h ;3DS AnalogVolumeHP' ;/ right? ;HWCAL[2E2h] TSC[65h:1Bh]=07h ;3DS AnalogVolumeSP ;\maybe left? ;HWCAL[2E3h] TSC[65h:1Ch]=07h ;3DS AnalogVolumeSP' ;/ right? ;HWCAL[2E3h] TSC[65h:33h]=03h ;3DS MicrophoneBias ;HWCAL[2E6h] TSC[65h:41h]=00h+wait;3DS PGA_GAIN (mic) (bit0-5) ;HWCAL[2E8h] TSC[65h:42h]=02h+wait;3DS QuickCharge (what?) (bit0-1) ;HWCAL[2E7h] TSC[65h:47h,4Bh,4Ch,4Dh,4Eh,52h,53h] ;unused, but nonzero TSC[65h:77h]=94h/95h ;3DS ? (reset=94h, ORed with 01h) TSC[65h:78h] ;unused, but nonzero TSC[65h:7Ah]=01h ;3DS ? Page 67h,FBh (3DS Touchscreen/Circle Pad) TSC[67h:17h]=43h ;3DS ? TSC[67h:19h]=69h ;3DS ? TSC[67h:1Bh]=80h ;3DS ? TSC[67h:24h]=98h/18h ;3DS bit7=0=touchscreen.on ;bit2=1=has new touchdata? TSC[67h:25h]=43h/53h ;3DS bit5-2=0100b=touchscreen.on TSC[67h:26h]=00h/ECh ;3DS bit7=1=touchscreen.on ;bit1=1=had old touchdata? TSC[67h:27h]=11h ;3DS ? TSC[FBh:01h]=read ;3DS fifo 26x16bit; 5xTSC.x, 5xTSC.y, 8xCPAD.y, 8xCPAD.x
Edit: Are that "TIMER_sleepMs(nn)" based on timings from nintendo? I guess some of the delays might be there to avoid minor speaker noise during init, and some delays might be actually required for working initialization.
The old TSC datasheet mentions a 100us delay between SoftReset and Coefficient RAM initialization, something like that might be needed here, too. I have some doubts about needing a 40ms delay after SoftReset though.
Shutter volume is for the camera app probably. When you take a picture it plays this insanely loud shutter sound. Unknown how this is triggered/used.
The data for filterMic32/47 is the same but it is actually stored twice in the fallback calibration data struct. They may be different in the actual calibration for a 3DS. What i'm writing is the fallback calibration data which is hardcoded and only used if loading the calibration data from eMMC (config savegame which contains a copy of the data from the HWCAL files) fails.
There is no code uploading any other data than these filters. So no, i don't think these miniDSP instructions are ever used (if supported at all).
These sleeps are 1:1 what Nintendo does in their code. A few of them are probably only there to free some CPU time for other threads and others are required. Keep in mind this is some weird compatibility bodged CODEC/touchscreen chip. Not an actual TSC2117 so it may behave completely different at least when using the new regs.
Updated the code a final time. Some bug fixes and i swapped val and mask params for the mask reg function to match Nintendos code:
https://gist.github.com/profi200/492664 ... adbffb4aaf