My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arduino.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifdef __PLAT_LINUX__
  23. #include <iostream>
  24. #include "../../inc/MarlinConfig.h"
  25. #include "hardware/Clock.h"
  26. #include "../shared/Delay.h"
  27. // Interrupts
  28. void cli(void) { } // Disable
  29. void sei(void) { } // Enable
  30. // Time functions
  31. void _delay_ms(const int delay_ms) {
  32. delay(delay_ms);
  33. }
  34. uint32_t millis() {
  35. return (uint32_t)Clock::millis();
  36. }
  37. // This is required for some Arduino libraries we are using
  38. void delayMicroseconds(uint32_t us) {
  39. Clock::delayMicros(us);
  40. }
  41. extern "C" void delay(const int msec) {
  42. Clock::delayMillis(msec);
  43. }
  44. // IO functions
  45. // As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
  46. void pinMode(const pin_t pin, const uint8_t mode) {
  47. if (!VALID_PIN(pin)) return;
  48. Gpio::setMode(pin, mode);
  49. }
  50. void digitalWrite(pin_t pin, uint8_t pin_status) {
  51. if (!VALID_PIN(pin)) return;
  52. Gpio::set(pin, pin_status);
  53. }
  54. bool digitalRead(pin_t pin) {
  55. if (!VALID_PIN(pin)) return false;
  56. return Gpio::get(pin);
  57. }
  58. void analogWrite(pin_t pin, int pwm_value) { // 1 - 254: pwm_value, 0: LOW, 255: HIGH
  59. if (!VALID_PIN(pin)) return;
  60. Gpio::set(pin, pwm_value);
  61. }
  62. uint16_t analogRead(pin_t adc_pin) {
  63. if (!VALID_PIN(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin))) return 0;
  64. return Gpio::get(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin));
  65. }
  66. // **************************
  67. // Persistent Config Storage
  68. // **************************
  69. void eeprom_write_byte(unsigned char *pos, unsigned char value) {
  70. }
  71. unsigned char eeprom_read_byte(uint8_t * pos) { return '\0'; }
  72. void eeprom_read_block(void *__dst, const void *__src, size_t __n) { }
  73. void eeprom_update_block(const void *__src, void *__dst, size_t __n) { }
  74. char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s) {
  75. char format_string[20];
  76. snprintf(format_string, 20, "%%%d.%df", __width, __prec);
  77. sprintf(__s, format_string, __val);
  78. return __s;
  79. }
  80. int32_t random(int32_t max) {
  81. return rand() % max;
  82. }
  83. int32_t random(int32_t min, int32_t max) {
  84. return min + rand() % (max - min);
  85. }
  86. void randomSeed(uint32_t value) {
  87. srand(value);
  88. }
  89. int map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) {
  90. return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  91. }
  92. #endif // __PLAT_LINUX__