Yes it works but analogWrite() function is overwriting the output type (CNF0 which defines push-pull or open-drain) back to push-pull each time.
It is also setting CNF1 to change from general purpose output to Alternate function output, which I assume is to attach the timer to the output port.
Using pinMode() to set pin A0 to output mode first, the code below shows this behaviour:
pinMode(A0, "output");
console.log("Peek 0x40010800:", peek32(0x40010800));
poke32(0x40010800, (peek32(0x40010800) & (~0b1100)) | 0b0100); // mask out existing bits and set open drain
console.log("Peek 0x40010800:", peek32(0x40010800));
analogWrite(A0, 0.5, { freq : 100 } );
console.log("Peek 0x40010800:", peek32(0x40010800));
Output, comments added manually:
Peek 0x40010800: 3 // 0b0011 - pinMode(...) sets push-pull, normal pin function
Peek 0x40010800: 7 // 0b0111 - poke32(...) Set to open drain
Peek 0x40010800: 11 // 0b1011 - analogWrite(...) sets back to push-pull output, alternate pin function
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes it works but analogWrite() function is overwriting the output type (CNF0 which defines push-pull or open-drain) back to push-pull each time.
It is also setting CNF1 to change from general purpose output to Alternate function output, which I assume is to attach the timer to the output port.
Using pinMode() to set pin A0 to output mode first, the code below shows this behaviour:
Output, comments added manually: