diff --git a/GyverCore/boards.txt b/GyverCore/boards.txt index 3ad7aaf..946b4cf 100644 --- a/GyverCore/boards.txt +++ b/GyverCore/boards.txt @@ -66,6 +66,13 @@ nano.menu.boot.no.speeds.US1MHZ=666 ## CLOCK ## menu.clock=Clock +nano.menu.clock.external_20=External 20 MHz +nano.menu.clock.external_20.fuses.CKDIV8=1 +nano.menu.clock.external_20.fuses.CKSEL=111111 +nano.menu.clock.external_20.build.f_cpu=20000000L +nano.menu.clock.external_20.bootloader.suffix=atmega328 +nano.menu.clock.external_20.upload.speed={speeds.US16MHZ} + nano.menu.clock.external_16=External 16 MHz nano.menu.clock.external_16.fuses.CKDIV8=1 nano.menu.clock.external_16.fuses.CKSEL=111111 diff --git a/GyverCore/cores/arduino/GyverCore_gpio.cpp b/GyverCore/cores/arduino/GyverCore_gpio.cpp index 3e486fb..11eaa0c 100644 --- a/GyverCore/cores/arduino/GyverCore_gpio.cpp +++ b/GyverCore/cores/arduino/GyverCore_gpio.cpp @@ -90,11 +90,11 @@ bool digitalRead (uint8_t pin) { void digitalToggle(uint8_t pin) { if (pin < 8) { - bitToggle(PORTD, pin); + bitSet(PIND, pin); } else if (pin < 14) { - bitToggle(PORTB, (pin - 8)); + bitSet(PINB, (pin - 8)); } else if (pin < 20) { - bitToggle(PORTC, (pin - 14)); // Toggle pin state (for 'tone()') + bitSet(PINC, (pin - 14)); // Toggle pin state (for 'tone()') } } @@ -136,7 +136,7 @@ uint16_t analogRead(uint8_t pin) { ADMUX = (analog_reference << 6) | pin; // Set analog MUX & reference bitSet(ADCSRA, ADSC); // Start while (ADCSRA & (1 << ADSC)); // Wait - return ADCL | (ADCH << 8); // Return result + return ADC; // Return result } diff --git a/GyverCore/cores/arduino/GyverCore_uart.cpp b/GyverCore/cores/arduino/GyverCore_uart.cpp index 12bf7b6..047df8d 100644 --- a/GyverCore/cores/arduino/GyverCore_uart.cpp +++ b/GyverCore/cores/arduino/GyverCore_uart.cpp @@ -194,13 +194,13 @@ String GyverUart::readStringUntil(char terminator) { // ====================== WRITE =========================== /* // прямая запись без буфера -void GyverUart::write(byte data){ +void GyverUart::writeBuffer(byte data){ while (!(UCSR0A & (1<= UART_TX_BUFFER_SIZE) ? 0 : _UART_TX_BUFFER_HEAD + 1; // ждать освобождения места в буфере while ( (i + 1) == _UART_TX_BUFFER_TAIL); @@ -229,15 +229,19 @@ ISR(USART_TX_vect) { } } -void GyverUart::println(void) { - write('\r'); +void GyverUart::write(byte data) { + writeBuffer(data); startTransmission(); - write('\n'); +} + +void GyverUart::println(void) { + writeBuffer('\r'); + writeBuffer('\n'); startTransmission(); } void GyverUart::print(char data) { - write(data); + writeBuffer(data); startTransmission(); } void GyverUart::println(char data) { @@ -245,24 +249,23 @@ void GyverUart::println(char data) { println(); } -void GyverUart::print(int8_t data, byte base) {printHelper( (long) data, base);} +void GyverUart::print(int8_t data, byte base) {printHelper( (int32_t) data, base);} void GyverUart::print(uint8_t data, byte base) {printHelper( (uint32_t) data, base);} -void GyverUart::print(int16_t data, byte base) {printHelper( (long) data, base);} -void GyverUart::print(uint16_t data, byte base) {printHelper( (uint32_t) data, base);} -void GyverUart::print(int32_t data, byte base) {printHelper( (long) data, base);} -void GyverUart::print(uint32_t data, byte base) {printHelper( (uint32_t) data, base);} +void GyverUart::print(int16_t data, byte base) {printHelper( (int32_t) data, base);} +void GyverUart::print(uint16_t data, byte base) {printHelper( (uint32_t) data, base);} +void GyverUart::print(int32_t data, byte base) {printHelper( (int32_t) data, base);} +void GyverUart::print(uint32_t data, byte base) {printHelper( (uint32_t) data, base);} -void GyverUart::println(int8_t data, byte base) {printHelper( (long) data, base); println();} +void GyverUart::println(int8_t data, byte base) {printHelper( (int32_t) data, base); println();} void GyverUart::println(uint8_t data, byte base) {printHelper( (uint32_t) data, base); println();} -void GyverUart::println(int16_t data, byte base) {printHelper( (long) data, base); println();} +void GyverUart::println(int16_t data, byte base) {printHelper( (int32_t) data, base); println();} void GyverUart::println(uint16_t data, byte base) {printHelper( (uint32_t) data, base); println();} -void GyverUart::println(int32_t data, byte base) {printHelper( (long) data, base); println();} +void GyverUart::println(int32_t data, byte base) {printHelper( (int32_t) data, base); println();} void GyverUart::println(uint32_t data, byte base) {printHelper( (uint32_t) data, base); println();} - void GyverUart::printHelper(int32_t data, byte base) { if (data < 0) { - write(45); + writeBuffer(45); data = -data; } printHelper((uint32_t) data, base); @@ -297,18 +300,18 @@ void GyverUart::printBytes(uint32_t data) { } } for (int8_t i = amount; i >= 0; i--) { - write(bytes[i] + '0'); + writeBuffer(bytes[i] + '0'); } } void GyverUart::print(double data, byte decimals) { if (data < 0) { - write(45); + writeBuffer(45); data = -data; } uint32_t integer = data; printBytes(integer); - write(46); // точка + writeBuffer(46); // точка data -= integer; for (byte i = 0; i < decimals; i++) { data *= 10.0; diff --git a/GyverCore/cores/arduino/GyverCore_uart.h b/GyverCore/cores/arduino/GyverCore_uart.h index 5c1ac48..46465cf 100644 --- a/GyverCore/cores/arduino/GyverCore_uart.h +++ b/GyverCore/cores/arduino/GyverCore_uart.h @@ -4,6 +4,8 @@ // Версия 1.4 - либа собрана в класс // Версия 1.5 - добавлен буфер на отправку и flush // Версия 1.6 - ускорена запись и чтение +// Версия 1.7 - чуть оптимизирован код +// Версия 1.8 - пофикшен write (спасибо eugenebartosh) #ifndef GyverUART_h #define GyverUART_h @@ -61,6 +63,7 @@ public: void println(char data[]); private: + void writeBuffer(byte data); void printHelper(int32_t data, byte base); void printHelper(uint32_t data, byte base); void printBytes(uint32_t data); diff --git a/GyverCore/cores/arduino/GyverCore_uptime.cpp b/GyverCore/cores/arduino/GyverCore_uptime.cpp index b73c104..aa12288 100644 --- a/GyverCore/cores/arduino/GyverCore_uptime.cpp +++ b/GyverCore/cores/arduino/GyverCore_uptime.cpp @@ -4,41 +4,41 @@ /* функции времени и инициализация таймеров , АЦП*/ void init() { - cli(); - - /*************** ADC ***************/ - + cli(); + + /*************** ADC ***************/ + #ifndef ADC_PRESCALER #define ADC_PRESCALER 0x02 #endif - /****************************************************************** - * ADC prescaler: [ /2 ]-[ /4 ]-[ /8 ]-[ /16]-[ /32]-[ /64]-[/128] * - * ADC_PRESCALER: [0x01]-[0x02]-[0x03]-[0x04]-[0x05]-[0x06]-[0x07] * - ******************************************************************/ - ADCSRA = (1 << ADEN) | ADC_PRESCALER; - - - - /************ Timers ************/ - - TCCR0A = (1 << WGM01) | (1 << WGM00); - TCCR0B = (1 << CS01) | (1 << CS00); - #ifndef _GYVERCORE_NOMILLIS - TIMSK0 |= (1 << TOIE0); + /****************************************************************** +* ADC prescaler: [ /2 ]-[ /4 ]-[ /8 ]-[ /16]-[ /32]-[ /64]-[/128] * +* ADC_PRESCALER: [0x01]-[0x02]-[0x03]-[0x04]-[0x05]-[0x06]-[0x07] * +******************************************************************/ + ADCSRA = (1 << ADEN) | ADC_PRESCALER; + + + + /************ Timers ************/ + + TCCR0A = (1 << WGM01) | (1 << WGM00); + TCCR0B = (1 << CS01) | (1 << CS00); +#ifndef _GYVERCORE_NOMILLIS + TIMSK0 |= (1 << TOIE0); #endif - TCCR1A = (1 << WGM10); - TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); - - TCCR2A = (1 << WGM20); - TCCR2B = (1 << CS22); - - - /************** USART **************/ - UCSR0B = 0x00; - - sei(); + TCCR1A = (1 << WGM10); + TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); + + TCCR2A = (1 << WGM20); + TCCR2B = (1 << CS22); + + + /************** USART **************/ + UCSR0B = 0x00; + + sei(); } @@ -86,9 +86,9 @@ unsigned long micros() { void delay(unsigned long ms) { #ifdef _GYVERCORE_NOMILLIS - while(ms){ - _delay_ms(ms); - ms--; + while(ms){ + _delay_ms(ms); + ms--; } #else uint32_t start = micros(); @@ -105,34 +105,48 @@ void delay(unsigned long ms) { void delayMicroseconds(unsigned int us) { #if F_CPU < 1000000L - _delay_us(us); + _delay_us(us); #else + -#if F_CPU >= 16000000L - if (us <= 1) return; // = 3 cycles, (4 when true) - us <<= 2; // x4 us, = 4 cycles - us -= 5; +#if F_CPU >= 24000000L + if (!us) return; // = 3 cycles, (4 when true) + us *= 6; // x6 us, = 7 cycles + us -= 5; //=2 cycles +#elif F_CPU >= 20000000L + __asm__ __volatile__ ( + "nop" "\n\t" + "nop" "\n\t" + "nop" "\n\t" + "nop"); //just waiting 4 cycles + if (us <= 1) return; // = 3 cycles, (4 when true) + us = (us << 2) + us; // x5 us, = 7 cycles + us -= 7; // 2 cycles +#elif F_CPU >= 16000000L + if (us <= 1) return; // = 3 cycles, (4 when true) + us <<= 2; // x4 us, = 4 cycles + us -= 5; #elif F_CPU >= 8000000L - if (us <= 2) return; // = 3 cycles, (4 when true) - us <<= 1; //x2 us, = 2 cycles - us -= 4; // = 2 cycles + if (us <= 2) return; // = 3 cycles, (4 when true) + us <<= 1; //x2 us, = 2 cycles + us -= 4; // = 2 cycles #elif F_CPU >= 1000000L - if (us <= 16) return; //= 3 cycles, (4 when true) - if (us <= 25) return; //= 3 cycles, (4 when true) - us -= 22; // = 2 cycles - us >>= 2; // us div 4, = 4 cycles + if (us <= 16) return; //= 3 cycles, (4 when true) + if (us <= 25) return; //= 3 cycles, (4 when true) + us -= 22; // = 2 cycles + us >>= 2; // us div 4, = 4 cycles #endif - asm volatile - ( - "loop_%=: \n\t" + asm volatile + ( + "loop_%=: \n\t" "sbiw %[counter],1 \n\t" // 2 cycles - "brne loop_%= \n\t" - : [counter]"=w" (us) - : "0" (us) // 2 cycles - ); - - // return = 4 cycles + "brne loop_%= \n\t" + : [counter]"=w" (us) + : "0" (us) // 2 cycles + ); + + // return = 4 cycles #endif } diff --git a/GyverCore/cores/arduino/main.cpp b/GyverCore/cores/arduino/main.cpp index 29f8b2d..738e94d 100644 --- a/GyverCore/cores/arduino/main.cpp +++ b/GyverCore/cores/arduino/main.cpp @@ -1,6 +1,6 @@ /* Главный цикл программы */ #pragma message "Нас тут заперли, вызовите 911!" -#pragma message "GyverCore v2.0.1 inside. Enjoy" +#pragma message "GyverCore v2.0.2 inside. Enjoy" #include diff --git a/README.md b/README.md index 48c4cb8..61ccfb3 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ parseFloat | 1070 | 246 | 824 - Вариант **without bootloader** для прошивки скетча во всю доступную (32 кБ) память МК --- **Clock** - выбор частоты и источника тактирования **(требует перезаписи загрузчика)**: +- **External 20 MHz** (макс. частота для ATmega328, для своих плат) - **External 16 MHz** (стандартный вариант для платы Nano 16 МГц) - **External 8 MHz** (стандартный вариант для платы Nano 8 МГц) - **Internal 8 MHz** (внутренний генератор: можно работать с голым камнем без кварца) @@ -293,4 +294,9 @@ parseFloat | 1070 | 246 | 824 - Исправлены ошибки в пустых загрузчиках - 2.0.1 - Исправлена ошибка с delayMicroseconds - - Исправлено предупреждение файла у "без загрузчика" \ No newline at end of file + - Исправлено предупреждение файла у "без загрузчика" +- 2.0.2 + - Ускорен digitalToggle + - Обновлён uart + - Чуть ускорен analogRead + - Добавлена поддержка клока 20 МГц \ No newline at end of file diff --git a/Release v2.0/GyverCore_linux.zip b/Release v2.0.2/GyverCore_linux.zip similarity index 99% rename from Release v2.0/GyverCore_linux.zip rename to Release v2.0.2/GyverCore_linux.zip index 23496ac..f6e337f 100644 Binary files a/Release v2.0/GyverCore_linux.zip and b/Release v2.0.2/GyverCore_linux.zip differ diff --git a/Release v2.0/GyverCore_win32.zip b/Release v2.0.2/GyverCore_win32.zip similarity index 99% rename from Release v2.0/GyverCore_win32.zip rename to Release v2.0.2/GyverCore_win32.zip index 33cd1db..118e20c 100644 Binary files a/Release v2.0/GyverCore_win32.zip and b/Release v2.0.2/GyverCore_win32.zip differ diff --git a/Release v2.0/GyverCore_win64.zip b/Release v2.0.2/GyverCore_win64.zip similarity index 99% rename from Release v2.0/GyverCore_win64.zip rename to Release v2.0.2/GyverCore_win64.zip index e8e15cf..47e1f5a 100644 Binary files a/Release v2.0/GyverCore_win64.zip and b/Release v2.0.2/GyverCore_win64.zip differ diff --git a/package_GyverCore_index.json b/package_GyverCore_index.json index 850486b..1aa00c8 100644 --- a/package_GyverCore_index.json +++ b/package_GyverCore_index.json @@ -330,6 +330,20 @@ {"name": "ATmega328 based boards"} ], "toolsDependencies": [] + }, + { + "name": "GyverCore", + "architecture": "avr", + "version": "2.0.2", + "category": "Contributed", + "url": "https://github.com/AlexGyver/GyverCore/releases/download/GyverCore-2.0.2/GyverCore.zip", + "archiveFileName": "GyverCore.zip", + "checksum": "MD5:81c4dc9d256ae55647b1002d56801f1e", + "size": "59050976", + "boards": [ + {"name": "ATmega328 based boards"} + ], + "toolsDependencies": [] } ], "tools": []