summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorJeff Epler <jeff@adafruit.com>2020-06-25 11:08:40 -0500
committerGitHub <noreply@github.com>2020-06-25 11:08:40 -0500
commit07eb7d653cad9e1381dce4ab544b9bd0012b3a4b (patch)
tree6eb4eb4535fd378ba5288ca36d5807e01b763535 /shared-bindings
parent3abdf744d586b288def6bd6b5385a1813a4fd984 (diff)
parentd768d4d37a1118768d6749c955bc4b0a82a66161 (diff)
Merge pull request #3042 from kamtom480/gnss
Add gnss module
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/gnss/GNSS.c227
-rw-r--r--shared-bindings/gnss/GNSS.h49
-rw-r--r--shared-bindings/gnss/PositionFix.c108
-rw-r--r--shared-bindings/gnss/PositionFix.h50
-rw-r--r--shared-bindings/gnss/SatelliteSystem.c145
-rw-r--r--shared-bindings/gnss/SatelliteSystem.h55
-rw-r--r--shared-bindings/gnss/__init__.c53
7 files changed, 687 insertions, 0 deletions
diff --git a/shared-bindings/gnss/GNSS.c b/shared-bindings/gnss/GNSS.c
new file mode 100644
index 000000000..929e02ab8
--- /dev/null
+++ b/shared-bindings/gnss/GNSS.c
@@ -0,0 +1,227 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/gnss/GNSS.h"
+#include "shared-bindings/time/__init__.h"
+#include "shared-bindings/util.h"
+
+#include "py/objproperty.h"
+#include "py/runtime.h"
+
+//| class GNSS:
+//| """Get updated positioning information from Global Navigation Satellite System (GNSS)
+//|
+//| Usage::
+//|
+//| import gnss
+//| import time
+//|
+//| nav = gnss.GNSS([gnss.SatelliteSystem.GPS, gnss.SatelliteSystem.GLONASS])
+//| last_print = time.monotonic()
+//| while True:
+//| nav.update()
+//| current = time.monotonic()
+//| if current - last_print >= 1.0:
+//| last_print = current
+//| if nav.fix is gnss.PositionFix.INVALID:
+//| print("Waiting for fix...")
+//| continue
+//| print("Latitude: {0:.6f} degrees".format(nav.latitude))
+//| print("Longitude: {0:.6f} degrees".format(nav.longitude))"""
+//|
+
+//| def __init__(self, ):
+//| """Turn on the GNSS.
+//|
+//| :param gnss.SatelliteSystem system: satellite system to use"""
+//| ...
+//|
+STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+ gnss_obj_t *self = m_new_obj(gnss_obj_t);
+ self->base.type = &gnss_type;
+ enum { ARG_system };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_system, MP_ARG_REQUIRED | MP_ARG_OBJ },
+ };
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ unsigned long selection = 0;
+ if (MP_OBJ_IS_TYPE(args[ARG_system].u_obj, &gnss_satellitesystem_type)) {
+ selection |= gnss_satellitesystem_obj_to_type(args[ARG_system].u_obj);
+ } else if (MP_OBJ_IS_TYPE(args[ARG_system].u_obj, &mp_type_list)) {
+ size_t systems_size = 0;
+ mp_obj_t *systems;
+ mp_obj_list_get(args[ARG_system].u_obj, &systems_size, &systems);
+ for (size_t i = 0; i < systems_size; ++i) {
+ if (!MP_OBJ_IS_TYPE(systems[i], &gnss_satellitesystem_type)) {
+ mp_raise_TypeError(translate("System entry must be gnss.SatelliteSystem"));
+ }
+ selection |= gnss_satellitesystem_obj_to_type(systems[i]);
+ }
+ } else {
+ mp_raise_TypeError(translate("System entry must be gnss.SatelliteSystem"));
+ }
+
+ common_hal_gnss_construct(self, selection);
+ return MP_OBJ_FROM_PTR(self);
+}
+
+//| def deinit(self, ) -> Any:
+//| """Turn off the GNSS."""
+//| ...
+//|
+STATIC mp_obj_t gnss_obj_deinit(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ common_hal_gnss_deinit(self);
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_deinit_obj, gnss_obj_deinit);
+
+STATIC void check_for_deinit(gnss_obj_t *self) {
+ if (common_hal_gnss_deinited(self)) {
+ raise_deinited_error();
+ }
+}
+
+//| def update(self, ) -> Any:
+//| """Update GNSS positioning information."""
+//| ...
+//|
+STATIC mp_obj_t gnss_obj_update(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ check_for_deinit(self);
+
+ common_hal_gnss_update(self);
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_update_obj, gnss_obj_update);
+
+//| latitude: Any = ...
+//| """Latitude of current position in degrees (float)."""
+//|
+STATIC mp_obj_t gnss_obj_get_latitude(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ check_for_deinit(self);
+ return mp_obj_new_float(common_hal_gnss_get_latitude(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_latitude_obj, gnss_obj_get_latitude);
+
+const mp_obj_property_t gnss_latitude_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&gnss_get_latitude_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| longitude: Any = ...
+//| """Longitude of current position in degrees (float)."""
+//|
+STATIC mp_obj_t gnss_obj_get_longitude(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ check_for_deinit(self);
+ return mp_obj_new_float(common_hal_gnss_get_longitude(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_longitude_obj, gnss_obj_get_longitude);
+
+const mp_obj_property_t gnss_longitude_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&gnss_get_longitude_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| altitude: Any = ...
+//| """Altitude of current position in meters (float)."""
+//|
+STATIC mp_obj_t gnss_obj_get_altitude(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ check_for_deinit(self);
+ return mp_obj_new_float(common_hal_gnss_get_altitude(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_altitude_obj, gnss_obj_get_altitude);
+
+const mp_obj_property_t gnss_altitude_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&gnss_get_altitude_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| timestamp: Any = ...
+//| """Time when the position data was updated."""
+//|
+STATIC mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ check_for_deinit(self);
+ timeutils_struct_time_t tm;
+ common_hal_gnss_get_timestamp(self, &tm);
+ return struct_time_from_tm(&tm);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_timestamp_obj, gnss_obj_get_timestamp);
+
+const mp_obj_property_t gnss_timestamp_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&gnss_get_timestamp_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+//| fix: Any = ...
+//| """Fix mode."""
+//|
+STATIC mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) {
+ gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ check_for_deinit(self);
+ return gnss_positionfix_type_to_obj(common_hal_gnss_get_fix(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_fix_obj, gnss_obj_get_fix);
+
+const mp_obj_property_t gnss_fix_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&gnss_get_fix_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = {
+ { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gnss_deinit_obj) },
+ { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&gnss_update_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) },
+ { MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) },
+ { MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) },
+ { MP_ROM_QSTR(MP_QSTR_timestamp), MP_ROM_PTR(&gnss_timestamp_obj) },
+ { MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) }
+};
+STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table);
+
+const mp_obj_type_t gnss_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_GNSS,
+ .make_new = gnss_make_new,
+ .locals_dict = (mp_obj_dict_t*)&gnss_locals_dict,
+};
diff --git a/shared-bindings/gnss/GNSS.h b/shared-bindings/gnss/GNSS.h
new file mode 100644
index 000000000..61ae35b12
--- /dev/null
+++ b/shared-bindings/gnss/GNSS.h
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H
+
+#include "common-hal/gnss/GNSS.h"
+#include "shared-bindings/gnss/SatelliteSystem.h"
+#include "shared-bindings/gnss/PositionFix.h"
+
+#include "lib/timeutils/timeutils.h"
+
+extern const mp_obj_type_t gnss_type;
+
+void common_hal_gnss_construct(gnss_obj_t *self, unsigned long selection);
+void common_hal_gnss_deinit(gnss_obj_t *self);
+bool common_hal_gnss_deinited(gnss_obj_t *self);
+void common_hal_gnss_update(gnss_obj_t *self);
+
+mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self);
+mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self);
+mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self);
+void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm);
+gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self);
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H
diff --git a/shared-bindings/gnss/PositionFix.c b/shared-bindings/gnss/PositionFix.c
new file mode 100644
index 000000000..106a28c34
--- /dev/null
+++ b/shared-bindings/gnss/PositionFix.c
@@ -0,0 +1,108 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/gnss/PositionFix.h"
+
+//| class PositionFix:
+//| """Position fix mode"""
+//|
+//| def __init__(self, ):
+//| """Enum-like class to define the position fix mode."""
+//|
+//| INVALID: Any = ...
+//| """No measurement.
+//|
+//| :type gnss.PositionFix:"""
+//|
+//| FIX_2D: Any = ...
+//| """2D fix.
+//|
+//| :type gnss.PositionFix:"""
+//|
+//| FIX_3D: Any = ...
+//| """3D fix.
+//|
+//| :type gnss.PositionFix:"""
+//|
+const mp_obj_type_t gnss_positionfix_type;
+
+const gnss_positionfix_obj_t gnss_positionfix_invalid_obj = {
+ { &gnss_positionfix_type },
+};
+
+const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj = {
+ { &gnss_positionfix_type },
+};
+
+const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj = {
+ { &gnss_positionfix_type },
+};
+
+gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj) {
+ gnss_positionfix_t posfix = POSITIONFIX_INVALID;
+ if (obj == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) {
+ posfix = POSITIONFIX_2D;
+ } else if (obj == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) {
+ posfix = POSITIONFIX_3D;
+ }
+ return posfix;
+}
+
+mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t posfix) {
+ switch (posfix) {
+ case POSITIONFIX_2D:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix2d_obj);
+ case POSITIONFIX_3D:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix3d_obj);
+ case POSITIONFIX_INVALID:
+ default:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_invalid_obj);
+ }
+}
+
+STATIC const mp_rom_map_elem_t gnss_positionfix_locals_dict_table[] = {
+ {MP_ROM_QSTR(MP_QSTR_INVALID), MP_ROM_PTR(&gnss_positionfix_invalid_obj)},
+ {MP_ROM_QSTR(MP_QSTR_FIX_2D), MP_ROM_PTR(&gnss_positionfix_fix2d_obj)},
+ {MP_ROM_QSTR(MP_QSTR_FIX_3D), MP_ROM_PTR(&gnss_positionfix_fix3d_obj)},
+};
+STATIC MP_DEFINE_CONST_DICT(gnss_positionfix_locals_dict, gnss_positionfix_locals_dict_table);
+
+STATIC void gnss_positionfix_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
+ qstr posfix = MP_QSTR_INVALID;
+ if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) {
+ posfix = MP_QSTR_FIX_2D;
+ } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) {
+ posfix = MP_QSTR_FIX_3D;
+ }
+ mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_PositionFix, posfix);
+}
+
+const mp_obj_type_t gnss_positionfix_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_PositionFix,
+ .print = gnss_positionfix_print,
+ .locals_dict = (mp_obj_t)&gnss_positionfix_locals_dict,
+};
diff --git a/shared-bindings/gnss/PositionFix.h b/shared-bindings/gnss/PositionFix.h
new file mode 100644
index 000000000..64497cb59
--- /dev/null
+++ b/shared-bindings/gnss/PositionFix.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H
+
+#include "py/obj.h"
+
+typedef enum {
+ POSITIONFIX_INVALID,
+ POSITIONFIX_2D,
+ POSITIONFIX_3D,
+} gnss_positionfix_t;
+
+const mp_obj_type_t gnss_positionfix_type;
+
+gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj);
+mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t mode);
+
+typedef struct {
+ mp_obj_base_t base;
+} gnss_positionfix_obj_t;
+extern const gnss_positionfix_obj_t gnss_positionfix_invalid_obj;
+extern const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj;
+extern const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj;
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H
diff --git a/shared-bindings/gnss/SatelliteSystem.c b/shared-bindings/gnss/SatelliteSystem.c
new file mode 100644
index 000000000..badc02b96
--- /dev/null
+++ b/shared-bindings/gnss/SatelliteSystem.c
@@ -0,0 +1,145 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/gnss/SatelliteSystem.h"
+
+//| class SatelliteSystem:
+//| """Satellite system type"""
+//|
+//| def __init__(self, ):
+//| """Enum-like class to define the satellite system type."""
+//|
+//| GPS: Any = ...
+//| """Global Positioning System.
+//|
+//| :type gnss.SatelliteSystem:"""
+//|
+//| GLONASS: Any = ...
+//| """GLObal NAvigation Satellite System.
+//|
+//| :type gnss.SatelliteSystem:"""
+//|
+//| SBAS: Any = ...
+//| """Satellite Based Augmentation System.
+//|
+//| :type gnss.SatelliteSystem:"""
+//|
+//| QZSS_L1CA: Any = ...
+//| """Quasi-Zenith Satellite System L1C/A.
+//|
+//| :type gnss.SatelliteSystem:"""
+//|
+//| QZSS_L1S: Any = ...
+//| """Quasi-Zenith Satellite System L1S.
+//|
+//| :type gnss.SatelliteSystem:"""
+//|
+const mp_obj_type_t gnss_satellitesystem_type;
+
+const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj = {
+ { &gnss_satellitesystem_type },
+};
+
+const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj = {
+ { &gnss_satellitesystem_type },
+};
+
+const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj = {
+ { &gnss_satellitesystem_type },
+};
+
+const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj = {
+ { &gnss_satellitesystem_type },
+};
+
+const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj = {
+ { &gnss_satellitesystem_type },
+};
+
+gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj) {
+ if (obj == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) {
+ return SATELLITESYSTEM_GPS;
+ } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) {
+ return SATELLITESYSTEM_GLONASS;
+ } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) {
+ return SATELLITESYSTEM_SBAS;
+ } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) {
+ return SATELLITESYSTEM_QZSS_L1CA;
+ } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) {
+ return SATELLITESYSTEM_QZSS_L1S;
+ }
+ return SATELLITESYSTEM_NONE;
+}
+
+mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t system) {
+ switch (system) {
+ case SATELLITESYSTEM_GPS:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_gps_obj);
+ case SATELLITESYSTEM_GLONASS:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_glonass_obj);
+ case SATELLITESYSTEM_SBAS:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_sbas_obj);
+ case SATELLITESYSTEM_QZSS_L1CA:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj);
+ case SATELLITESYSTEM_QZSS_L1S:
+ return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj);
+ case SATELLITESYSTEM_NONE:
+ default:
+ return (mp_obj_t)MP_ROM_PTR(&mp_const_none_obj);
+ }
+}
+
+STATIC const mp_rom_map_elem_t gnss_satellitesystem_locals_dict_table[] = {
+ {MP_ROM_QSTR(MP_QSTR_GPS), MP_ROM_PTR(&gnss_satellitesystem_gps_obj)},
+ {MP_ROM_QSTR(MP_QSTR_GLONASS), MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)},
+ {MP_ROM_QSTR(MP_QSTR_SBAS), MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)},
+ {MP_ROM_QSTR(MP_QSTR_QZSS_L1CA), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)},
+ {MP_ROM_QSTR(MP_QSTR_QZSS_L1S), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)},
+};
+STATIC MP_DEFINE_CONST_DICT(gnss_satellitesystem_locals_dict, gnss_satellitesystem_locals_dict_table);
+
+STATIC void gnss_satellitesystem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
+ qstr system = MP_QSTR_None;
+ if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) {
+ system = MP_QSTR_GPS;
+ } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) {
+ system = MP_QSTR_GLONASS;
+ } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) {
+ system = MP_QSTR_SBAS;
+ } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) {
+ system = MP_QSTR_QZSS_L1CA;
+ } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) {
+ system = MP_QSTR_QZSS_L1S;
+ }
+ mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_SatelliteSystem, system);
+}
+
+const mp_obj_type_t gnss_satellitesystem_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_SatelliteSystem,
+ .print = gnss_satellitesystem_print,
+ .locals_dict = (mp_obj_t)&gnss_satellitesystem_locals_dict,
+};
diff --git a/shared-bindings/gnss/SatelliteSystem.h b/shared-bindings/gnss/SatelliteSystem.h
new file mode 100644
index 000000000..484e861ab
--- /dev/null
+++ b/shared-bindings/gnss/SatelliteSystem.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H
+
+#include "py/obj.h"
+
+typedef enum {
+ SATELLITESYSTEM_NONE = 0,
+ SATELLITESYSTEM_GPS = (1U << 0),
+ SATELLITESYSTEM_GLONASS = (1U << 1),
+ SATELLITESYSTEM_SBAS = (1U << 2),
+ SATELLITESYSTEM_QZSS_L1CA = (1U << 3),
+ SATELLITESYSTEM_QZSS_L1S = (1U << 4),
+} gnss_satellitesystem_t;
+
+const mp_obj_type_t gnss_satellitesystem_type;
+
+gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj);
+mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t mode);
+
+typedef struct {
+ mp_obj_base_t base;
+} gnss_satellitesystem_obj_t;
+extern const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj;
+extern const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj;
+extern const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj;
+extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj;
+extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj;
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H
diff --git a/shared-bindings/gnss/__init__.c b/shared-bindings/gnss/__init__.c
new file mode 100644
index 000000000..b3cf722f1
--- /dev/null
+++ b/shared-bindings/gnss/__init__.c
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "py/obj.h"
+#include "py/runtime.h"
+#include "py/mphal.h"
+#include "shared-bindings/gnss/GNSS.h"
+#include "shared-bindings/gnss/SatelliteSystem.h"
+#include "shared-bindings/gnss/PositionFix.h"
+#include "shared-bindings/util.h"
+
+//| """Global Navigation Satellite System
+//|
+//| The `gnss` module contains classes to control the GNSS and acquire positioning information."""
+//|
+STATIC const mp_rom_map_elem_t gnss_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gnss) },
+ { MP_ROM_QSTR(MP_QSTR_GNSS), MP_ROM_PTR(&gnss_type) },
+
+ // Enum-like Classes.
+ { MP_ROM_QSTR(MP_QSTR_SatelliteSystem), MP_ROM_PTR(&gnss_satellitesystem_type) },
+ { MP_ROM_QSTR(MP_QSTR_PositionFix), MP_ROM_PTR(&gnss_positionfix_type) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(gnss_module_globals, gnss_module_globals_table);
+
+const mp_obj_module_t gnss_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&gnss_module_globals,
+};