Cursor is an AI-powered VSCode fork so PlatformIO just works. I use it at work all day long (mainly python for machine learning) but it works great with Arduino code!
It’s helpful in debugging
Porting code between MCUs:
//set frequency in Hz, pulse length in units of 64mus
void setFreq(int f, int len) {
// much of the code in this section originated from https://www.instructables.com/Portable-Precision-Stroboscope/
//calculate what to put into the timing registers
long unsigned int ticks = (160000000 + f / 2) / f; // f_clock/0.1f
unsigned int ps = 1;
if (ticks > 0xFFFF) ps = 8;
if (ticks > 8 * 0xFFFF) ps = 64;
if (ticks > 64 * 0xFFFF) ps = 256;
if (ticks > 256 * 0xFFFF) ps = 1024;
unsigned int val_ICR1 = ticks / ps - 1;
unsigned int val_OCR1B = len * (1024 / ps) - 1;
unsigned int val_TCCR1B = B00011001;
if (ps == 8) val_TCCR1B = B00011010;
if (ps == 64) val_TCCR1B = B00011011;
if (ps == 256) val_TCCR1B = B00011100;
if (ps == 1024) val_TCCR1B = B00011101;
// set the actual values in the timing registers
// ICR is the "Input Capture Register." You can set up the timer so that when the ICRn pin changes,
// the timer value at that instant is copied (by hardware) to the ICR, where you SW can read it "later."
// So if you read the ICR at each edge of a pulse on that input pin, you can measure the length of the pulse.
// OCR is the "Output Compare Register." When the timer counter value matches the value you've put in the OCR,
// the module does "something."
// noInterrupts();
if (TCNT1 > val_ICR1) TCNT1 = 0; //do not allow timer to exceed 'top'
ICR1 = val_ICR1;
OCR1B = val_OCR1B;
TCCR1B = val_TCCR1B;
I gave the following direction: This was built for a Arduino Mega2560. Port it to a esp32-s3-devkitc-1
As with all AI-powered coding tools, it hallucinates and makes mistakes but in general it’s quite intelligent.
This is just scratching the surface.